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

[5.6] Fix for HasManyThrough returning incorrect results with cursor(… #25015

Merged
merged 1 commit into from
Jul 30, 2018
Merged
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
10 changes: 10 additions & 0 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,16 @@ public function chunk($count, callable $callback)
return $this->prepareQueryBuilder()->chunk($count, $callback);
}

/**
* Get a generator for the given query.
*
* @return \Generator
*/
public function cursor()
{
return $this->prepareQueryBuilder()->cursor();
}

/**
* Execute a callback over each item while chunking.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Database/DatabaseEloquentHasManyThroughIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,27 @@ public function testChunkReturnsCorrectModels()
});
}

public function testCursorReturnsCorrectModels()
{
$this->seedData();
$this->seedDataExtended();
$country = HasManyThroughTestCountry::find(2);

$posts = $country->posts()->cursor();

foreach ($posts as $post) {
$this->assertEquals([
'id',
'user_id',
'title',
'body',
'email',
'created_at',
'updated_at',
'country_id', ], array_keys($post->getAttributes()));
}
}

public function testEachReturnsCorrectModels()
{
$this->seedData();
Expand Down