Skip to content

Commit

Permalink
[5.6] Fix for HasManyThrough returning incorrect results with cursor() (
Browse files Browse the repository at this point in the history
  • Loading branch information
Ammar Rahman committed Jul 30, 2018
1 parent 919eff2 commit 999e7fe
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
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

0 comments on commit 999e7fe

Please sign in to comment.