Skip to content

Commit 887045b

Browse files
michaellee8-iclasschrishardinge
authored andcommitted
fix BelongsTo returns integer causing SQL to fail
1 parent c0dac39 commit 887045b

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

src/Illuminate/Database/Eloquent/Relations/BelongsTo.php

+3-4
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,10 @@ protected function getEagerModelKeys(array $models)
127127
}
128128
}
129129

130-
// If there are no keys that were not null we will just return an array with either
131-
// null or 0 in (depending on if incrementing keys are in use) so the query wont
132-
// fail plus returns zero results, which should be what the developer expects.
130+
// If there are no keys that were not null we will just return an array with null
131+
// so the query wont fail plus returns zero results, which should be what the developer expects.
133132
if (count($keys) === 0) {
134-
return [$this->relationHasIncrementingId() ? 0 : null];
133+
return [null];
135134
}
136135

137136
sort($keys);

tests/Database/DatabaseEloquentBelongsToTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function testAssociateMethodSetsForeignKeyOnModelById()
103103
public function testDefaultEagerConstraintsWhenIncrementing()
104104
{
105105
$relation = $this->getRelation();
106-
$relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([0]));
106+
$relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([null]));
107107
$models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub];
108108
$relation->addEagerConstraints($models);
109109
}

0 commit comments

Comments
 (0)