Having trouble writing my sql statement in drizzle. Want to join two variables
I am trying to execute this sql statement with drizzle
But I am having trouble translating this to code. I am currently doing something like this:
But it's giving me the object two times with only one entity attached. Maybe my sql knowledge isnt up to date or im missing something in drizzle. Are there some examples i could look at?
4 Replies
Can you share the table definitions?
In your SQL I see that you are selecting from
relation table and joining on the entity table twice.
Can't see the same thing in the drizzle translation.Yeah ofcourse:
I've tried:
But i get a
Alias "entity" is already used in this query
Oh wait, is it because I am not adding aliases?Not sure but can you try this:
If you want to join the same table twice you can use an alias and instead of the
or you can do two leftJoins.Joins [SQL] - Drizzle ORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
Using the given query I still get 2 results, two times the same relation but with a different entity attached.
I've tried doing:
But that still gives me
Alias "entity" is already used in this query
Oh I see my mistake
That works 😄
Now to get them as names
Perfect