circular foreign keys

I have separate files for each table:
export const productVariant = pgTable("product_variant", {
id: serial("id").primaryKey(),
defaultPackageSizeId: integer("default_package_size_id")
.notNull()
.references(() => packageSize.id),
});


export const packageSize = pgTable("package_size", {
id: serial("id").primaryKey(),
productVariantId: integer("product_variant_id").references(
() => productVariant.id
),
});
export const productVariant = pgTable("product_variant", {
id: serial("id").primaryKey(),
defaultPackageSizeId: integer("default_package_size_id")
.notNull()
.references(() => packageSize.id),
});


export const packageSize = pgTable("package_size", {
id: serial("id").primaryKey(),
productVariantId: integer("product_variant_id").references(
() => productVariant.id
),
});
but this does not work, error:
packageSize implicitly has type
because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
packageSize implicitly has type
because it does not have a type annotation and is referenced directly or indirectly in its own initializer.
How to fix it?
Solution:
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
...
Jump to solution
2 Replies
Solution
tzezar
tzezar12mo ago
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
defaultPackageSizeId: integer("default_package_size_id").references(
(): AnyPgColumn => packageSize.id
),
tzezar
tzezarOP12mo ago
this works
Want results from more Discord servers?
Add your server