[5.3] Allow loading specific columns while eagerloading - #16327
Conversation
|
How about when we are eager loading nested relationships, and want to select columns on both the direct and distant relations ? |
|
@shadoWalker89 don't use this syntax :) Just use a closure for more advanced queries. |
|
Might be useful to note that you have to include id in the specified columns. Therefore the following doesn't work: |
|
@themsaid really cool, is nice and clean. Would it be possible having: User::where(...)->with('business:id,name')->get()To add some spaces: User::where(...)->with('business: id, name')->get() |
|
I think it looks nicer without spaces tbh. |
|
Would be out of line with the rest of the framework to support spaces there I think. |
|
I think it looks nicer with spaces |
|
I am having some difficulties aliasing the primaryKey here. It does not seem to work with the closure. Example: MyModel::with(['relation' => function($q) {
$q->select('primaryId as id', 'foo as bar');
});This will return null, while the following: MyModel::with(['relation' => function($q) {
$q->select('primaryId', 'primaryId as id', 'foo as bar');
});Will work, but will also return a primaryId key that I don't need. |
This allows for:
Which is equivalent to: