ArwanceR
ArwanceR
DTDrizzle Team
Created by ArwanceR on 7/26/2023 in #help
Relational query problem
My goal is to get object of this shape:
product: {
...
images: [{...}, {...}, {...}]
}
product: {
...
images: [{...}, {...}, {...}]
}
Product has relation to images - one-to-many,
export const productRelations = relations(products, ({ many}) => ({
images: many(images)
}))
export const productRelations = relations(products, ({ many}) => ({
images: many(images)
}))
and according to the docs: https://orm.drizzle.team/docs/joins#many-to-one-example I should be able to do this:
const products = await db.select().from(products)
.leftJoin(images, eq(images.productId, products.id)).all()
const products = await db.select().from(products)
.leftJoin(images, eq(images.productId, products.id)).all()
(using postgres) However, apparently, method all() does not exist and I get an error: db.select(...).from(...).leftJoin(...).all is not a function. If I'm doing something wrong please tell me.
3 replies