TypeError: Cannot read properties of undefined (reading 'referencedTable')

Here is the relational query that I'm trying to execute (Turso SQLite):
const result = db.query.product
.findMany({
where: (product) => inArray(product.id, keys),
with: {
seller: true,
},
})
.execute();
const result = db.query.product
.findMany({
where: (product) => inArray(product.id, keys),
with: {
seller: true,
},
})
.execute();
Here is the schema:
export const product = sqliteTable(
"product",
{
id: text("id").notNull().primaryKey(),
...
sellerId: text("sellerId")
.notNull()
.references(() => user.id),
},
(product) => ({
sellerIdx: index("sellerIdx").on(product.sellerId),
}),
);
export const product = sqliteTable(
"product",
{
id: text("id").notNull().primaryKey(),
...
sellerId: text("sellerId")
.notNull()
.references(() => user.id),
},
(product) => ({
sellerIdx: index("sellerIdx").on(product.sellerId),
}),
);
export const user = sqliteTable(
"user",
{

id: text("id").notNull().primaryKey(),
}).notNull(),
...
},
(user) => ({
nameIdx: uniqueIndex("nameIdx").on(user.name),
}),
);
export const user = sqliteTable(
"user",
{

id: text("id").notNull().primaryKey(),
}).notNull(),
...
},
(user) => ({
nameIdx: uniqueIndex("nameIdx").on(user.name),
}),
);
export const productRelations = relations(product, ({ one, many }) => ({
seller: one(user, {
fields: [product.sellerId],
references: [user.id],
}),
}));
export const productRelations = relations(product, ({ one, many }) => ({
seller: one(user, {
fields: [product.sellerId],
references: [user.id],
}),
}));
export const userRelations = relations(user, ({ one, many }) => ({
products: many(product),
}));
export const userRelations = relations(user, ({ one, many }) => ({
products: many(product),
}));
Everytime I run relational query "with:{seller:true}" it throws error. In Drizzlekit studio, the product references seller just fine. What's wrong?
5 Replies
miho
miho16mo ago
I'm expericing the exact same issue 🤷‍♂️
miho
miho16mo ago
I forgot to export the relations 🤦‍♂️ After that, no more erorr 👍
No description
No description
Pachimari
PachimariOP16mo ago
how did you get rid of the error by just exporting the relations? In my example im exporting relations and still getting the same error
miho
miho16mo ago
I don't know what to tell you 🤷‍♂️ I'm still new to Drizzle myself 1. Setup the schema 2. Setup the relations 3. Create migrations 4. Migrate 4. Use with { with: clips }
Demnu
Demnu14mo ago
Make sure to import the relations when you declare your schema const db = drizzle(databaseClient, { schema: { products, recipes, orders, orders_products, orderRelations, ordersProductsRelations } }); like so
Want results from more Discord servers?
Add your server