I'm using laravel 3 do to eager loading. What I've noticed is it works great! Until I use either ->select(['fields')
or ->paginate( , ['fields'])
to select a subset of the model's attributes. When I do this, it automatically culls any eager loaded model, which results in the relationship being NULL. Any clean way around this?
Asked
Active
Viewed 66 times
0

Authman Apatira
- 3,994
- 1
- 26
- 33
1 Answers
0
You have to also select the fields of the relationship table:
->select(array(
'table1.column',
'table2.column',
...
));

Ruke
- 141
- 5
-
Works w/ joins... but not with eager loading, e.g. model::with('relationship')->select(['model.column','relationship.column']) will only pull model.column – Authman Apatira Jul 12 '14 at 02:07
-
You're right. I was inspecting the code, and apparently there is no way of doing this without modifying the framework (not even with an anonymous function with $query->select(...);). – Ruke Jul 13 '14 at 00:21