Is it possible to make circular references? #236
-
Example: a category with a parent reference export const category = pgTable(
"Category",
{
id: uuid("id").primaryKey(),
name: varchar("name"),
parentCategoryId: uuid("parentCategoryId").references(() => category.id),
}
)
// error: 'category' implicitly has type 'any' because it does not have a type annotation
// and is referenced directly or indirectly in its own initializer. Is it possible to do this without having to create a complex type annotation? |
Beta Was this translation helpful? Give feedback.
Answered by
dankochetov
Mar 8, 2023
Replies: 1 comment 2 replies
-
Yes, you can use the 3rd argument in export const category = pgTable(
'Category',
{
id: uuid('id').primaryKey(),
name: varchar('name'),
parentCategoryId: uuid('parentCategoryId'),
},
(category) => ({
selfRef: foreignKey({
columns: [category.parentCategoryId],
foreignColumns: [category.id],
}),
}),
); |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
dankochetov
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Yes, you can use the 3rd argument in
pgTable
: