Skip to content

Commit

Permalink
Merge branch '10.x' into 11.x
Browse files Browse the repository at this point in the history
# Conflicts:
#	CHANGELOG.md
#	src/Illuminate/Foundation/Application.php
#	tests/Database/DatabaseEloquentModelTest.php
#	tests/Http/JsonResourceTest.php
  • Loading branch information
driesvints committed Jul 30, 2024
2 parents d4b5c64 + 639a2ee commit 49938bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -3259,10 +3259,10 @@ protected function runPaginationCountQuery($columns = ['*'])
->get()->all();
}

$without = $this->unions ? ['orders', 'limit', 'offset'] : ['columns', 'orders', 'limit', 'offset'];
$without = $this->unions ? ['unionOrders', 'unionLimit', 'unionOffset'] : ['columns', 'orders', 'limit', 'offset'];

return $this->cloneWithout($without)
->cloneWithoutBindings($this->unions ? ['order'] : ['select', 'order'])
->cloneWithoutBindings($this->unions ? ['unionOrder'] : ['select', 'order'])
->setAggregate('count', $this->withoutSelectAliases($columns))
->get()->all();
}
Expand Down
28 changes: 28 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2231,6 +2231,34 @@ public function testGetCountForPaginationWithUnion()
$this->assertEquals(1, $count);
}

public function testGetCountForPaginationWithUnionOrders()
{
$builder = $this->getBuilder();
$builder->from('posts')->select('id')->union($this->getBuilder()->from('videos')->select('id'))->latest();

$builder->getConnection()->shouldReceive('select')->once()->with('select count(*) as aggregate from ((select "id" from "posts") union (select "id" from "videos")) as "temp_table"', [], true)->andReturn([['aggregate' => 1]]);
$builder->getProcessor()->shouldReceive('processSelect')->once()->andReturnUsing(function ($builder, $results) {
return $results;
});

$count = $builder->getCountForPagination();
$this->assertEquals(1, $count);
}

public function testGetCountForPaginationWithUnionLimitAndOffset()
{
$builder = $this->getBuilder();
$builder->from('posts')->select('id')->union($this->getBuilder()->from('videos')->select('id'))->take(15)->skip(1);

$builder->getConnection()->shouldReceive('select')->once()->with('select count(*) as aggregate from ((select "id" from "posts") union (select "id" from "videos")) as "temp_table"', [], true)->andReturn([['aggregate' => 1]]);
$builder->getProcessor()->shouldReceive('processSelect')->once()->andReturnUsing(function ($builder, $results) {
return $results;
});

$count = $builder->getCountForPagination();
$this->assertEquals(1, $count);
}

public function testWhereShortcut()
{
$builder = $this->getBuilder();
Expand Down

0 comments on commit 49938bd

Please sign in to comment.