Circular Reference in Schema Relation

I'm trying the following:
export const pages = pgTable("pages", {
  ...shared,
  // primaryMetadataId: uuid()
  //   .unique()
  //   .references(() => metadata.id, { onDelete: "cascade" }),
});

export const metadata = pgTable("metadata", {
  ...shared,
  pageId: uuid()
    .notNull()
    .references(() => pages.id, { onDelete: "cascade" }),
});

As soon as I uncomment the primaryMetadataId, I get a bunch of typescript errors. In this case every metadata should belong to a page but the page may select one as "primary". I believe this could be done with a join table, but I'd rather just have the schema clean
Was this page helpful?