Lucid : how to use ORM relationships to make join requests #3856
Replies: 1 comment
-
You tried this package? |
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
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, I'm trying to leverage the ORM and relationships of Lucid instead of using .join() in the query builder.
In join(), I have to use table names and column names, which for me loses the added value of an ORM.
Here is the relevant model :
I want to filter my Interventions based on a criteria not directly present in the table.
The Intervention references an Engin which itself references a Stf which has the column of interest.
This is a working code using the ModelQueryBuilder :
It creates the following output:

I have to use preload() otherwise the
mr
field and it'sstf
field are not populated.The problem is that under the hood Lucid (and Knex) does 3 requests to achieve this result:
When the same thing can be expressed like this in pure SQL:
Here are my questions :
Beta Was this translation helpful? Give feedback.
All reactions