I think you can also eager load the routine relation when loading the progress
something along the lines of
Records::with("progress.routine")
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Forgive me if the title is not clearly stated. I have this particular problem (perhaps due to the initial design of the database relation). Is it possible to use the columns in parent together with the columns in child ( via eager load with([]) ) as a constrain to the grand-child?
I have 3 tables. Let's call them
The relation between them are as follows:
There is no direct relation between Records and Routine. It can be said that Routine are just logs.
In order to retrieve Routine for specific Records. Routine must use two parent relation, 1 column (Routine.Serial) matches with Progress another column (Routine.Date) matches with Records.
I was able to eager load (or Lazy Load) Records and Progress. However I couldn't do so to eager load Routine below Progress with additional constrain from Records
How can I use the "Date" in Records and "Serial" in Progress as constrain to retrieve Routine via eager loading.
If it's impossible, then I'll have to run into the N+1 query problem as I have to lookup for each Progress in order to retrieve the Routine.
p/s: Is there any 'preview' function before I open discussion?
Please or to participate in this conversation.