how to query based on relation?

I have many to many relation between Project and User table. How to querry all projects that user is into? db.query.projects.findMany({ where: ---> users include userId ? with: { users: true, }, });
1 Reply
samson
samson7mo ago
your where statement could look something like this. Hard to tell without your exact schema.
where: inArray(users.id, allUserIdsThatShouldBeIncluded)
where: inArray(users.id, allUserIdsThatShouldBeIncluded)
or you can do a leftJoin() and filter at that point:
db.select().from(projects).leftJoin(users, and(eq(projects.userId,users.id), inArray(users.id, allUserIdsThatShouldBeIncluded
db.select().from(projects).leftJoin(users, and(eq(projects.userId,users.id), inArray(users.id, allUserIdsThatShouldBeIncluded
Want results from more Discord servers?
Add your server