Skip to content

Is it possible to make circular references? #236

Answered by dankochetov
mattiaz9 asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use the 3rd argument in pgTable:

export const category = pgTable(
	'Category',
	{
		id: uuid('id').primaryKey(),
		name: varchar('name'),
		parentCategoryId: uuid('parentCategoryId'),
	},
	(category) => ({
		selfRef: foreignKey({
			columns: [category.parentCategoryId],
			foreignColumns: [category.id],
		}),
	}),
);

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@mattiaz9
Comment options

@mattiaz9
Comment options

Answer selected by dankochetov
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants