Is it possible to have nested values when doing a leftJoin?
If not, what is your approach when you're not using the query builder? Should I map the results and enrich them based on the
financialInstitutionId
? Or is there something I missed?17 Replies
Anyone? 😅
can you give an example of what 1st approach returns and what you're looking for ?
Sure
The first example returns:
The second example returns:
In the first case, the
financialInsitution
is nested in the loan object, as expected.
I understand a pure SQL join would produce the same "non-nested" results, although it would be nice to have the same format. If I miss something in the doc, I would be happy to read more about it. If not, I'm interested how people handle this.I see, have you thought about using a subquery?
I did not
How would you do that?
modifying second example:
this might need some modifications, such as selecting more fields in
select({})
mmh it seems a bit hacky no? 😅 I could check how they implemented
with
, but I'm unsure I will be able to decipher everything 🙈well, I there was another solution, I would too use it : )
this is one solution, you might find other
Yeah thank you for your input, I'll check the source and in parallel hope someone will jump in as well 😉
you can turn logging on and check the generated query with this 'working' example
what sql it generates
Ho, I didn't think about it
know where to put it ?
I suppose in the main instance
unless we can activate logging per request also?
I don't think you can turn on logging per request
but, to turn it on for all queries:
but, that being said, I don't think sql will make you find other solution, since it's raw
if there's no other API you will still have to use some workaround
https://github.com/drizzle-team/drizzle-orm/blob/5b01a4ff112935ff5433c3437476a5aa1d86ceab/drizzle-orm/src/relations.ts#L416C17-L416C34
They normalize the relations at some point
I will stop digging at the moment and use the query builder. I was asking the question as I expect at some point I'll have more complex queries.
So in the end, it's either do like them or do like you I believe 🙂
thanks for the brainstorm, always help 🙂
happy to help
Joins [SQL] – DrizzleORM
Drizzle ORM | %s