How can I eager load only specific columns from a polymorphic relationship?
I have a people
table that morphs to users and bots, from where I only need to load first_name
and last_name
for a specific query.
I've tried this solution with no luck, since it doesn't seem to apply for polymorphic relationships... it simply ignores the ->select()
and loads everything as it should.
Any Ideas?
EDIT : Here is the relevant query
$school->load(array(
'associationsTeachers' => function($q){
$q->with(array(
'person' => function($q2){
$q2->with(array(
'account' => function($q3){
$q3->select(array('id', 'first_name', 'last_name', 'person_id', 'account_id', 'account_type' ));
}
));
},
));
}
));
And here are the the relations
Person
table: 'people';
public function account(){
return $this->morphTo();
}
User
table: 'users'
public function person(){
return $this->morphOne('Person', 'account');
}
Bot
table: 'bots'
public function person(){
return $this->morphOne('Person', 'account');
}