laravel - Polymorphic nested eager loading with constraints -


i have classes:

students-----{id,profile_id,year}  profiles-----{id}  subjects-----{id}-is learnable  groupssbj-----{id}-is learnable  learnables----{profile_id,learnable_id,learnable_type,year}  groupssbj_subject--{subject_id,groupsbj_id} 

i want load student id 5, , it's profile, , learnables of profile learnables.year=student.year go lazy loading

$student = student::find(5); $student->load(['profile.subjects'=>function($query) use($student){                             $query->wherepivot('year','=',$student->year);                         }],['profile.groupssbj'=>function($query) use($student){                             $query->wherepivot('year','=',$student->year);                         }],'profile.groupssbj.subjects'); 

if call $student.profile.subjects subjects constrains, groups $student.profile.groupssbj not constrained, , if separate in 2 loads

$student = student::find(5); $student->load(['profile.subjects'=>function($query) use($student){                             $query->wherepivot('year','=',$student->year);                         }]); $student->load(['profile.groupssbj'=>function($query) use($student){                             $query->wherepivot('year','=',$student->year);                         }],'profile.groupssbj.subjects'); 

then groups being constrained right subjects don't, meaning loaded all. may constrain them writing query again i'm curious why behave that? there problem laravel relationship class or doing wrong cos never used polymorphic classes before


Comments

Popular posts from this blog

html - How to set bootstrap input responsive width? -

javascript - Highchart x and y axes data from json -

javascript - Get js console.log as python variable in QWebView pyqt -