There is not enough information to infer relation

Hello, I am running into a issue where drizzle studio is stating that there is not enought information to infer relation "__public__.tickets.chat". Any idea why this might be? I have the following schema:
export const tickets = pgTable("tickets", {
id: text("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
description: text("description").notNull(),
status: ticketStatus("status").notNull().default("awaiting"),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const ticketRelations = relations(tickets, ({ one, many }) => ({
chat: one(chats),
tickets: many(ticketsToUsers),
}));

export const chats = pgTable("chats", {
id: text("id").primaryKey(),
type: chatType("type").notNull(),
ticketID: text("ticket_id").references(() => tickets.id),
author: text("author").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const chatRelations = relations(chats, ({ many }) => ({
messages: many(chatMessages),
members: many(chatsToUsers),
}));
export const tickets = pgTable("tickets", {
id: text("id").primaryKey(),
title: varchar("title", { length: 255 }).notNull(),
description: text("description").notNull(),
status: ticketStatus("status").notNull().default("awaiting"),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const ticketRelations = relations(tickets, ({ one, many }) => ({
chat: one(chats),
tickets: many(ticketsToUsers),
}));

export const chats = pgTable("chats", {
id: text("id").primaryKey(),
type: chatType("type").notNull(),
ticketID: text("ticket_id").references(() => tickets.id),
author: text("author").notNull(),
createdAt: timestamp("created_at").notNull().defaultNow(),
});

export const chatRelations = relations(chats, ({ many }) => ({
messages: many(chatMessages),
members: many(chatsToUsers),
}));
4 Replies
Liam
LiamOP5mo ago
The weird thing is that as far as I can tell this is a one-to-one relation, so much of the advice on other tables does not apply here
Liam
LiamOP5mo ago
GitHub
HackKit/packages/db/schema.ts at dev · acmutsa/HackKit
Feature-packed Hackathon Managment Software. Contribute to acmutsa/HackKit development by creating an account on GitHub.
tzezar
tzezar5mo ago
I am not sure since i have not used drizzle for so long. Is your relations syntax correct? As i remember i had to set references field
Mario564
Mario5645mo ago
Hi there. In ticketRelations you're defining that a ticket has one chat, so in chatRelations, you need to define that a chat has many tickets or one ticket (not sure what the relationship is that you're aiming for) or remove the ticket and chat relation in ticketRelations (if the two are not meant to be related)
Want results from more Discord servers?
Add your server