Skip to content

Commit 49938bd

Browse files
committed
Merge branch '10.x' into 11.x
# Conflicts: # CHANGELOG.md # src/Illuminate/Foundation/Application.php # tests/Database/DatabaseEloquentModelTest.php # tests/Http/JsonResourceTest.php
2 parents d4b5c64 + 639a2ee commit 49938bd

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Illuminate/Database/Query/Builder.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3259,10 +3259,10 @@ protected function runPaginationCountQuery($columns = ['*'])
32593259
->get()->all();
32603260
}
32613261

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

32643264
return $this->cloneWithout($without)
3265-
->cloneWithoutBindings($this->unions ? ['order'] : ['select', 'order'])
3265+
->cloneWithoutBindings($this->unions ? ['unionOrder'] : ['select', 'order'])
32663266
->setAggregate('count', $this->withoutSelectAliases($columns))
32673267
->get()->all();
32683268
}

tests/Database/DatabaseQueryBuilderTest.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,6 +2231,34 @@ public function testGetCountForPaginationWithUnion()
22312231
$this->assertEquals(1, $count);
22322232
}
22332233

2234+
public function testGetCountForPaginationWithUnionOrders()
2235+
{
2236+
$builder = $this->getBuilder();
2237+
$builder->from('posts')->select('id')->union($this->getBuilder()->from('videos')->select('id'))->latest();
2238+
2239+
$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]]);
2240+
$builder->getProcessor()->shouldReceive('processSelect')->once()->andReturnUsing(function ($builder, $results) {
2241+
return $results;
2242+
});
2243+
2244+
$count = $builder->getCountForPagination();
2245+
$this->assertEquals(1, $count);
2246+
}
2247+
2248+
public function testGetCountForPaginationWithUnionLimitAndOffset()
2249+
{
2250+
$builder = $this->getBuilder();
2251+
$builder->from('posts')->select('id')->union($this->getBuilder()->from('videos')->select('id'))->take(15)->skip(1);
2252+
2253+
$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]]);
2254+
$builder->getProcessor()->shouldReceive('processSelect')->once()->andReturnUsing(function ($builder, $results) {
2255+
return $results;
2256+
});
2257+
2258+
$count = $builder->getCountForPagination();
2259+
$this->assertEquals(1, $count);
2260+
}
2261+
22342262
public function testWhereShortcut()
22352263
{
22362264
$builder = $this->getBuilder();

0 commit comments

Comments
 (0)