Skip to content

Commit

Permalink
Fix collection engine mapIds bug (#585)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir9480 authored Feb 15, 2022
1 parent 5c1db4e commit d50ed2f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Engines/CollectionEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,10 @@ protected function ensureSoftDeletesAreHandled($builder, $query)
*/
public function mapIds($results)
{
$results = $results['results'];
$results = array_values($results['results']);

return count($results) > 0
? collect($results)->pluck($results[0]->getKeyName())->values()
? collect($results)->pluck($results[0]->getKeyName())
: collect();
}

Expand Down
11 changes: 11 additions & 0 deletions tests/Feature/CollectionEngineTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,17 @@ public function test_it_can_paginate_results()

$models = SearchableUserModel::search('laravel')->paginate();
$this->assertCount(2, $models);

$dummyQuery = function ($query) {
$query->where('name', '!=', 'Dummy');
};
$models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 1);
$this->assertCount(1, $models);
$this->assertEquals('Abigail Otwell', $models[0]->name);

$models = SearchableUserModel::search('laravel')->query($dummyQuery)->orderBy('name')->paginate(1, 'page', 2);
$this->assertCount(1, $models);
$this->assertEquals('Taylor Otwell', $models[0]->name);
}

public function test_limit_is_applied()
Expand Down

0 comments on commit d50ed2f

Please sign in to comment.