diff --git a/src/Illuminate/Database/Eloquent/Builder.php b/src/Illuminate/Database/Eloquent/Builder.php index 6beefbf62276..0c39ea5fc571 100755 --- a/src/Illuminate/Database/Eloquent/Builder.php +++ b/src/Illuminate/Database/Eloquent/Builder.php @@ -223,9 +223,9 @@ public function orWhere($column, $operator = null, $value = null) * @param array $items * @return \Illuminate\Database\Eloquent\Collection */ - public function hydrate(array $items) + public function hydrate(array $items, $connection = null) { - $instance = $this->model->newInstance(); + $instance = $this->model->newInstance()->setConnection($connection); return $instance->newCollection(array_map(function ($item) use ($instance) { return $instance->newFromBuilder($item); @@ -244,7 +244,8 @@ public function fromQuery($query, $bindings = []) $instance = $this->model->newInstance(); return $this->hydrate( - $instance->getConnection()->select($query, $bindings) + $instance->getConnection()->select($query, $bindings), + $this->query->getConnection()->getName() ); } @@ -460,7 +461,7 @@ public function getModels($columns = ['*']) { return $this->model->hydrate( $this->query->get($columns)->all(), - $this->model->getConnectionName() + $this->query->getConnection()->getName() )->all(); } diff --git a/tests/Database/DatabaseEloquentIntegrationTest.php b/tests/Database/DatabaseEloquentIntegrationTest.php index 33ca8553fe7f..028b149572f5 100644 --- a/tests/Database/DatabaseEloquentIntegrationTest.php +++ b/tests/Database/DatabaseEloquentIntegrationTest.php @@ -1061,6 +1061,14 @@ public function testBelongsToManyCustomPivot() $this->assertEquals('Jule Doe', $johnWithFriends->friends->find(4)->pivot->friend->name); } + public function testIsAfterRetrievingTheSameModel() + { + $saved = EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']); + $retrieved = EloquentTestUser::find(1); + + $this->assertTrue($saved->is($retrieved)); + } + /** * Helpers... */