Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for is() method #18760

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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()
);
}

Expand Down Expand Up @@ -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();
}

Expand Down
8 changes: 8 additions & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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...
*/
Expand Down