No, in this case you every time end up with 3 queries.
May 17, 2020
4
Level 2
Possible to fill related models with a single query?
Say you have models Widget, Lookup1, Lookup2. Lookup1 & Lookup2 are lookup tables where Widget belongsTo Lookup1 and belongsTo Lookup2.
If I just Widget::find(1) and in the template I call $widget->lookup1 and $widget->lookup2 I will end up with 3 queries.
If I try to Widget::find(1)->with(['Lookup1','Lookup2']) I also end up with 3 queries.
If I try ->join('table','first','=','second') they query works correctly but the models aren't populated and again I end up with 3 queries
Is there a way to perform a join of all the lookups and have the models be populated?
Please or to participate in this conversation.