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

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -