You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[10.x] Fix cursor paginate with union and column alias (#50882)
* Cursor paginate uses incorrect column name for where on union
* Set the right column names for the cursor on the unions
* Add dedicated test to test correct column alias on union cursor paginate
* Add eloquent test for cursor pagination with union and multiple aliases
* Use correct column name in cursor where clause
Copy file name to clipboardExpand all lines: tests/Database/DatabaseQueryBuilderTest.php
+54-5Lines changed: 54 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -5276,7 +5276,7 @@ public function testCursorPaginateWithUnionWheres()
5276
5276
5277
5277
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5278
5278
$this->assertEquals(
5279
-
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" > ?)) union (select "id", "created_at", \'news\' as type from "news" where ("start_time" > ?)) order by "created_at" asc limit 17',
5279
+
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" > ?)) union (select "id", "created_at", \'news\' as type from "news" where ("created_at" > ?)) order by "created_at" asc limit 17',
@@ -5325,7 +5325,7 @@ public function testCursorPaginateWithMultipleUnionsAndMultipleWheres()
5325
5325
5326
5326
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5327
5327
$this->assertEquals(
5328
-
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" > ?)) union (select "id", "created_at", \'news\' as type from "news" where "extra" = ? and ("start_time" > ?)) union (select "id", "created_at", \'podcast\' as type from "podcasts" where "extra" = ? and ("start_time" > ?)) order by "created_at" asc limit 17',
5328
+
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" > ?)) union (select "id", "created_at", \'news\' as type from "news" where "extra" = ? and ("created_at" > ?)) union (select "id", "created_at", \'podcast\' as type from "podcasts" where "extra" = ? and ("created_at" > ?)) order by "created_at" asc limit 17',
@@ -5422,7 +5422,7 @@ public function testCursorPaginateWithUnionWheresWithRawOrderExpression()
5422
5422
5423
5423
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5424
5424
$this->assertEquals(
5425
-
'(select "id", "is_published", "start_time" as "created_at", \'video\' as type from "videos" where "is_published" = ? and ("start_time" > ?)) union (select "id", "is_published", "created_at", \'news\' as type from "news" where "is_published" = ? and ("start_time" > ?)) order by case when (id = 3 and type="news" then 0 else 1 end), "created_at" asc limit 17',
5425
+
'(select "id", "is_published", "start_time" as "created_at", \'video\' as type from "videos" where "is_published" = ? and ("start_time" > ?)) union (select "id", "is_published", "created_at", \'news\' as type from "news" where "is_published" = ? and ("created_at" > ?)) order by case when (id = 3 and type="news" then 0 else 1 end), "created_at" asc limit 17',
@@ -5469,7 +5469,7 @@ public function testCursorPaginateWithUnionWheresReverseOrder()
5469
5469
5470
5470
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5471
5471
$this->assertEquals(
5472
-
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ?)) union (select "id", "created_at", \'news\' as type from "news" where ("start_time" < ?)) order by "created_at" desc limit 17',
5472
+
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ?)) union (select "id", "created_at", \'news\' as type from "news" where ("created_at" < ?)) order by "created_at" desc limit 17',
@@ -5516,7 +5516,7 @@ public function testCursorPaginateWithUnionWheresMultipleOrders()
5516
5516
5517
5517
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5518
5518
$this->assertEquals(
5519
-
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ? or ("start_time" = ? and ("id" > ?)))) union (select "id", "created_at", \'news\' as type from "news" where ("start_time" < ? or ("start_time" = ? and ("id" > ?)))) order by "created_at" desc, "id" asc limit 17',
5519
+
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" < ? or ("start_time" = ? and ("id" > ?)))) union (select "id", "created_at", \'news\' as type from "news" where ("created_at" < ? or ("created_at" = ? and ("id" > ?)))) order by "created_at" desc, "id" asc limit 17',
$builder->shouldReceive('get')->once()->andReturnUsing(function () use ($builder, $results, $ts) {
5567
+
$this->assertEquals(
5568
+
'(select "id", "start_time" as "created_at", \'video\' as type from "videos" where ("start_time" > ?)) union (select "id", "created_at", \'news\' as type from "news" where ("created_at" > ?)) union (select "id", "init_at" as "created_at", \'podcast\' as type from "podcasts" where ("init_at" > ?)) order by "created_at" asc limit 17',
0 commit comments