Relational query problem
My goal is to get object of this shape:
Product has relation to
images
- one-to-many,
and according to the docs: https://orm.drizzle.team/docs/joins#many-to-one-example
I should be able to do this:
(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.2 Replies
the
all
is for SQLite (see the import in that code snippet) and is not needed for postgres.
Also note that the relation you defined will not work with
db.select()...
you have to use the RQB like db.query.products.findMany({ with: { images: true} })
See https://orm.drizzle.team/docs/rqb#foreign-keys for more information.Relational queries – DrizzleORM
Drizzle ORM | %s
Ah ok, thank you for your answer. I know I could do this with findMany()` but I wanted to try do it the other way, so I could include aggregating function which is not supported "as of now" with relational queries.