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
- Add default `ORDER BY` primary key when no order is specified to ensure deterministic pagination results ([#73](https://github.com/aarondfrancis/fast-paginate/issues/73))
$queries = $this->withQueriesLogged(function () use (&$results) {
157
+
$results = User::query()->fastPaginate(5);
158
+
});
159
+
160
+
// Inner query should have order by primary key to ensure deterministic results
161
+
$this->assertEquals(
162
+
'select `users`.`id` from `users` order by `users`.`id` asc limit 5 offset 0',
163
+
$queries[1]['query']
164
+
);
165
+
166
+
// Outer query should also preserve the order
167
+
$this->assertEquals(
168
+
'select * from `users` where `users`.`id` in (1, 2, 3, 4, 5) order by `users`.`id` asc limit 6 offset 0',
169
+
$queries[2]['query']
170
+
);
171
+
}
172
+
153
173
#[Test]
154
174
publicfunctionorder_is_propagated()
155
175
{
@@ -211,15 +231,15 @@ public function selects_are_overwritten()
211
231
$results = User::query()->selectRaw('(select 1 as complicated_subquery)')->fastPaginate();
212
232
});
213
233
214
-
// Dropped for our inner query
234
+
// Dropped for our inner query (default order by primary key is added)
215
235
$this->assertEquals(
216
-
'select `users`.`id` from `users` limit 15 offset 0',
236
+
'select `users`.`id` from `users` order by `users`.`id` asc limit 15 offset 0',
217
237
$queries[1]['query']
218
238
);
219
239
220
-
// Restored for the user's query
240
+
// Restored for the user's query (with default order)
221
241
$this->assertEquals(
222
-
'select (select 1 as complicated_subquery) from `users` where `users`.`id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) limit 16 offset 0',
242
+
'select (select 1 as complicated_subquery) from `users` where `users`.`id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) order by `users`.`id` asc limit 16 offset 0',
223
243
$queries[2]['query']
224
244
);
225
245
}
@@ -327,7 +347,7 @@ public function uuids_are_bound_correctly()
327
347
328
348
$this->assertCount(3, $queries);
329
349
$this->assertEquals(
330
-
'select * from `notifications` where `notifications`.`id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) limit 16 offset 0',
350
+
'select * from `notifications` where `notifications`.`id` in (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) order by `notifications`.`id` asc limit 16 offset 0',
331
351
$queries[2]['query']
332
352
);
333
353
@@ -363,7 +383,7 @@ public function basic_simple_test()
363
383
$this->assertCount(2, $queries);
364
384
365
385
$this->assertEquals(
366
-
'select * from `users` where `users`.`id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) limit 16 offset 0',
386
+
'select * from `users` where `users`.`id` in (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15) order by `users`.`id` asc limit 16 offset 0',
367
387
$queries[1]['query']
368
388
);
369
389
@@ -385,7 +405,7 @@ public function basic_simple_test_page_two()
385
405
$this->assertCount(2, $queries);
386
406
387
407
$this->assertEquals(
388
-
'select * from `users` where `users`.`id` in (6, 7, 8, 9, 10) limit 6 offset 0',
408
+
'select * from `users` where `users`.`id` in (6, 7, 8, 9, 10) order by `users`.`id` asc limit 6 offset 0',
389
409
$queries[1]['query']
390
410
);
391
411
@@ -407,7 +427,7 @@ public function basic_simple_test_from_relation()
407
427
$this->assertCount(3, $queries);
408
428
409
429
$this->assertEquals(
410
-
'select * from `posts` where `posts`.`user_id` = ? and `posts`.`user_id` is not null and `posts`.`id` in (1) limit 16 offset 0',
430
+
'select * from `posts` where `posts`.`user_id` = ? and `posts`.`user_id` is not null and `posts`.`id` in (1) order by `posts`.`id` asc limit 16 offset 0',
Copy file name to clipboardExpand all lines: tests/Integration/RelationTest.php
+1-1Lines changed: 1 addition & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -20,7 +20,7 @@ public function basic_test()
20
20
});
21
21
22
22
$this->assertEquals(
23
-
'select * from `posts` where `posts`.`user_id` = ? and `posts`.`user_id` is not null and `posts`.`id` in (1) limit 16 offset 0',
23
+
'select * from `posts` where `posts`.`user_id` = ? and `posts`.`user_id` is not null and `posts`.`id` in (1) order by `posts`.`id` asc limit 16 offset 0',
0 commit comments