Replies: 2 comments
-
Does it work with a raw SQL query? |
Beta Was this translation helpful? Give feedback.
0 replies
-
@cr101 Thanks for the tip! I spent years with Prisma and forgot to check on this. For anyone who is coming from an ORM like Prisma, Drizzle resembles SQL closely. So to do the above function, the SQL will be: SELECT user.id, user.email
FROM User user
INNER JOIN _OrganisationToUser organisation ON user.id = organisation.B
WHERE user.email = 'hello@example.com' AND organisation.A = 'organisationId'; In drizzle, this will look like: const user = await db
.select()
.from(user)
.innerJoin(organisationToUser, eq(organisationToUser.b, user.id))
.where(
and(
eq(user.email, 'hello@example.com'),
eq(organisationToUser.a, 'organisationId'),
),
); |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
For example, I have three tables as follows:
User:
Organisation:
OrganisationToUser:
One user has many organisations and one organisation have many users. This is a Planetscale database so no foreign keys. Only virtual relationships. In this case, how can I filter users with their email and organisationId? Here's something I tried:
Unfortunately, this does not work. It only filters the user's existing organisations but still return the user. Any idea how can I get this done?
Beta Was this translation helpful? Give feedback.
All reactions