File tree Expand file tree Collapse file tree 2 files changed +9
-9
lines changed
src/Illuminate/Database/Eloquent/Relations Expand file tree Collapse file tree 2 files changed +9
-9
lines changed Original file line number Diff line number Diff line change @@ -116,16 +116,16 @@ public function addEagerConstraints(array $models)
116
116
*/
117
117
protected function getEagerModelKeys (array $ models )
118
118
{
119
+ $ keys = [];
120
+
119
121
// First we need to gather all of the keys from the parent models so we know what
120
122
// to query for via the eager loading query. We will add them to an array then
121
123
// execute a "where in" statement to gather up all of those related records.
122
- $ keys = collect ($ models )->map (function ($ model ) {
123
- return $ model ->{$ this ->foreignKey };
124
- })->filter (function ($ value ) {
125
- return (! is_null ($ value )) &&
126
- (! is_bool ($ value ) || $ value !== false ) &&
127
- (! is_string ($ value ) || $ value !== '' );
128
- })->all ();
124
+ foreach ($ models as $ model ) {
125
+ if (! is_null ($ value = $ model ->{$ this ->foreignKey })) {
126
+ $ keys [] = $ value ;
127
+ }
128
+ }
129
129
130
130
// If there are no keys that were not null we will just return an array with either
131
131
// null or 0 in (depending on if incrementing keys are in use) so the query wont
Original file line number Diff line number Diff line change @@ -37,7 +37,7 @@ public function testIdsInEagerConstraintsCanBeZero()
37
37
{
38
38
$ relation = $ this ->getRelation ();
39
39
$ relation ->getQuery ()->shouldReceive ('whereIn ' )->once ()->with ('relation.id ' , ['foreign.value ' , 0 ]);
40
- $ models = [new EloquentBelongsToModelStub , new EloquentBelongsToModelStubWithIdZero ];
40
+ $ models = [new EloquentBelongsToModelStub , new EloquentBelongsToModelStubWithZeroId ];
41
41
$ relation ->addEagerConstraints ($ models );
42
42
}
43
43
@@ -151,7 +151,7 @@ class AnotherEloquentBelongsToModelStub extends \Illuminate\Database\Eloquent\Mo
151
151
public $ foreign_key = 'foreign.value.two ' ;
152
152
}
153
153
154
- class EloquentBelongsToModelStubWithIdZero extends \Illuminate \Database \Eloquent \Model
154
+ class EloquentBelongsToModelStubWithZeroId extends \Illuminate \Database \Eloquent \Model
155
155
{
156
156
public $ foreign_key = 0 ;
157
157
}
You can’t perform that action at this time.
0 commit comments