DT
Drizzle Team•12mo ago
Paul

Type issue when creating self join

I have the following:
export const medusaCategories = sqliteTable("medusa_categories", {
id: text("id").unique(),
createdAt: text("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: text("updated_at").default(sql`CURRENT_TIMESTAMP`),
deletedAt: text("deleted_at"),
// relations
storeId: text("store_id")
.references(() => medusaStores.id)
.notNull(),
parentId: text("parent_id").references(() => medusaCategories.id).notNull(),
});
export const medusaCategories = sqliteTable("medusa_categories", {
id: text("id").unique(),
createdAt: text("created_at")
.default(sql`CURRENT_TIMESTAMP`)
.notNull(),
updatedAt: text("updated_at").default(sql`CURRENT_TIMESTAMP`),
deletedAt: text("deleted_at"),
// relations
storeId: text("store_id")
.references(() => medusaStores.id)
.notNull(),
parentId: text("parent_id").references(() => medusaCategories.id).notNull(),
});
If I comment out parentId then I get the type for medusaCategories. Otherwise I get the error: 'medusaCategories' implicitly has type 'any' because it does not have a type annotation and is referenced directly or indirectly in its own initializer How to resolve? Thanks
2 Replies
Angelelz
Angelelz•12mo ago
Like this:
storeId: text("store_id")
.references((): AnySqliteColumn => medusaStores.id)
.notNull(),
parentId: text("parent_id").references((): AnySqliteColumn => medusaCategories.id).notNull(),
storeId: text("store_id")
.references((): AnySqliteColumn => medusaStores.id)
.notNull(),
parentId: text("parent_id").references((): AnySqliteColumn => medusaCategories.id).notNull(),
Paul
PaulOP•12mo ago
Nice, thank you so much for taking the time to answer my question! 😄
Want results from more Discord servers?
Add your server