From 771256b3e6adaae8725ad859eea54e46517d4e9e Mon Sep 17 00:00:00 2001 From: Michael Tsang Date: Fri, 16 Jun 2017 14:49:25 +0800 Subject: [PATCH] fix BelongsTo returns integer causing SQL to fail --- src/Illuminate/Database/Eloquent/Relations/BelongsTo.php | 7 +++---- tests/Database/DatabaseEloquentBelongsToTest.php | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php index e6dce103ec05..005b8ac4a8ae 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsTo.php @@ -127,11 +127,10 @@ protected function getEagerModelKeys(array $models) } } - // If there are no keys that were not null we will just return an array with either - // null or 0 in (depending on if incrementing keys are in use) so the query wont - // fail plus returns zero results, which should be what the developer expects. + // If there are no keys that were not null we will just return an array with null + // so the query wont fail plus returns zero results, which should be what the developer expects. if (count($keys) === 0) { - return [$this->relationHasIncrementingId() ? 0 : null]; + return [null]; } sort($keys); diff --git a/tests/Database/DatabaseEloquentBelongsToTest.php b/tests/Database/DatabaseEloquentBelongsToTest.php index 1edf1abdbb3b..a1a8db945a83 100755 --- a/tests/Database/DatabaseEloquentBelongsToTest.php +++ b/tests/Database/DatabaseEloquentBelongsToTest.php @@ -103,7 +103,7 @@ public function testAssociateMethodSetsForeignKeyOnModelById() public function testDefaultEagerConstraintsWhenIncrementing() { $relation = $this->getRelation(); - $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([0])); + $relation->getQuery()->shouldReceive('whereIn')->once()->with('relation.id', m::mustBe([null])); $models = [new MissingEloquentBelongsToModelStub, new MissingEloquentBelongsToModelStub]; $relation->addEagerConstraints($models); }