Syuro
DTDrizzle Team
•Created by Syuro on 3/1/2024 in #help
one-to-many self-relation
Hello, I'm trying to create a one-to-many self-relation but I get the error
There is not enough information to infer relation "comment.replies"
, i looked at the previous threads but it didn't seem to solve my problem
export const comment = pgTable("comment", {
id: uuid("id").notNull().unique().primaryKey().defaultRandom(),
parentId: uuid("parent_id"),
comment: text("comment").notNull(),
userId: uuid("user_id").references(() => users.id, { onDelete: "cascade" }).notNull(),
createdAt: timestamp("created_at").defaultNow(),
updatedAt: timestamp("updated_at").defaultNow(),
deleted: boolean("deleted").default(false),
})
export const commentRelations = relations(comment, (({ one, many }) => ({
user: one(users, {
fields: [comment.userId],
references: [users.id]
}),
replies: many(comment, { relationName: "replies" }),
})))
7 replies