How to query join table with db.query syntax?
Here is my schema for User, Library and LibraryUser tables..
9 Replies
I wanna get the all libraries for a user..
this doesn't work,
can
db.query
do this kind of query? do I have to use db.select()
and leftJoin
or something?
This works, I would like to db.query
though if possible.
are passing the relations into the schema property?
hmm?
this is not correct either..
You can't filter by a related table
The workaround is to use a subquery
Take a look at this post for an example
https://discord.com/channels/1043890932593987624/1303405402230100069
I didn't see any example in the post.
Is
db.query
worth it though? I always used db.select
but was trying out this recently, at first it seemed simple, but I think I'll stick with db.select
because complex queries like,
I don't know how you would do that with db.query
thing.
unless there is some benefit performance wise or something.. I think I'll stick with this.
this makes more sense when reading the query as well.i meant, when you are creating the db client. Are you passing the relations + schema into it? i noticed that if i didnt put those relations into it, the db.query would never work.
example:
Yes, I pass both.
Meant to use this one https://discord.com/channels/1043890932593987624/1291472979003314320/1291745731505426494
I see. I don't like this, it feels like a hack, I don't think this should be in a release but rather in a testing or dev branch. I think I'm gonna stick to
db.select()
.