Skip to content

Commit a3f3d7c

Browse files
authored
Add nulls_always_first and nulls_always_last to nulls_comparison (#4103)
1 parent 7f46a36 commit a3f3d7c

File tree

5 files changed

+151
-0
lines changed

5 files changed

+151
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* MongoDB: `date_immutable` support (#3940)
88
* DataProvider: Add `TraversablePaginator` (#3783)
99
* Swagger UI: Add `swagger_ui_extra_configuration` to Swagger / OpenAPI configuration (#3731)
10+
* OrderFilter: Add `nulls_always_first` and `nulls_always_last` to `nulls_comparison` (#4103)
1011

1112
## 2.6.3
1213

src/Bridge/Doctrine/Common/Filter/OrderFilterInterface.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ interface OrderFilterInterface
2626
public const DIRECTION_DESC = 'DESC';
2727
public const NULLS_SMALLEST = 'nulls_smallest';
2828
public const NULLS_LARGEST = 'nulls_largest';
29+
public const NULLS_ALWAYS_FIRST = 'nulls_always_first';
30+
public const NULLS_ALWAYS_LAST = 'nulls_always_last';
2931
public const NULLS_DIRECTION_MAP = [
3032
self::NULLS_SMALLEST => [
3133
'ASC' => 'ASC',
@@ -35,5 +37,13 @@ interface OrderFilterInterface
3537
'ASC' => 'DESC',
3638
'DESC' => 'ASC',
3739
],
40+
self::NULLS_ALWAYS_FIRST => [
41+
'ASC' => 'ASC',
42+
'DESC' => 'ASC',
43+
],
44+
self::NULLS_ALWAYS_LAST => [
45+
'ASC' => 'DESC',
46+
'DESC' => 'DESC',
47+
],
3848
];
3949
}

tests/Bridge/Doctrine/Common/Filter/OrderFilterTestTrait.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,62 @@ private function provideApplyTestArguments(): array
232232
],
233233
],
234234
],
235+
'nulls_always_first (asc)' => [
236+
[
237+
'dummyDate' => [
238+
'nulls_comparison' => 'nulls_always_first',
239+
],
240+
'name' => null,
241+
],
242+
[
243+
'order' => [
244+
'dummyDate' => 'asc',
245+
'name' => 'desc',
246+
],
247+
],
248+
],
249+
'nulls_always_first (desc)' => [
250+
[
251+
'dummyDate' => [
252+
'nulls_comparison' => 'nulls_always_first',
253+
],
254+
'name' => null,
255+
],
256+
[
257+
'order' => [
258+
'dummyDate' => 'desc',
259+
'name' => 'desc',
260+
],
261+
],
262+
],
263+
'nulls_always_last (asc)' => [
264+
[
265+
'dummyDate' => [
266+
'nulls_comparison' => 'nulls_always_last',
267+
],
268+
'name' => null,
269+
],
270+
[
271+
'order' => [
272+
'dummyDate' => 'asc',
273+
'name' => 'desc',
274+
],
275+
],
276+
],
277+
'nulls_always_last (desc)' => [
278+
[
279+
'dummyDate' => [
280+
'nulls_comparison' => 'nulls_always_last',
281+
],
282+
'name' => null,
283+
],
284+
[
285+
'order' => [
286+
'dummyDate' => 'desc',
287+
'name' => 'desc',
288+
],
289+
],
290+
],
235291
'not having order should not throw a deprecation (select unchanged)' => [
236292
[
237293
'id' => null,

tests/Bridge/Doctrine/MongoDbOdm/Filter/OrderFilterTest.php

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,70 @@ public function provideApplyTestData(): array
436436
],
437437
$orderFilterFactory,
438438
],
439+
'nulls_always_first (asc)' => [
440+
[
441+
[
442+
'$sort' => [
443+
'dummyDate' => 1,
444+
],
445+
],
446+
[
447+
'$sort' => [
448+
'dummyDate' => 1,
449+
'name' => -1,
450+
],
451+
],
452+
],
453+
$orderFilterFactory,
454+
],
455+
'nulls_always_first (desc)' => [
456+
[
457+
[
458+
'$sort' => [
459+
'dummyDate' => -1,
460+
],
461+
],
462+
[
463+
'$sort' => [
464+
'dummyDate' => -1,
465+
'name' => -1,
466+
],
467+
],
468+
],
469+
$orderFilterFactory,
470+
],
471+
'nulls_always_last (asc)' => [
472+
[
473+
[
474+
'$sort' => [
475+
'dummyDate' => 1,
476+
],
477+
],
478+
[
479+
'$sort' => [
480+
'dummyDate' => 1,
481+
'name' => -1,
482+
],
483+
],
484+
],
485+
$orderFilterFactory,
486+
],
487+
'nulls_always_last (desc)' => [
488+
[
489+
[
490+
'$sort' => [
491+
'dummyDate' => -1,
492+
],
493+
],
494+
[
495+
'$sort' => [
496+
'dummyDate' => -1,
497+
'name' => -1,
498+
],
499+
],
500+
],
501+
$orderFilterFactory,
502+
],
439503
'not having order should not throw a deprecation (select unchanged)' => [
440504
[],
441505
$orderFilterFactory,

tests/Bridge/Doctrine/Orm/Filter/OrderFilterTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,26 @@ public function provideApplyTestData(): array
265265
null,
266266
$orderFilterFactory,
267267
],
268+
'nulls_always_first (asc)' => [
269+
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank ASC, o.dummyDate ASC, o.name DESC', Dummy::class),
270+
null,
271+
$orderFilterFactory,
272+
],
273+
'nulls_always_first (desc)' => [
274+
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank ASC, o.dummyDate DESC, o.name DESC', Dummy::class),
275+
null,
276+
$orderFilterFactory,
277+
],
278+
'nulls_always_last (asc)' => [
279+
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank DESC, o.dummyDate ASC, o.name DESC', Dummy::class),
280+
null,
281+
$orderFilterFactory,
282+
],
283+
'nulls_always_last (desc)' => [
284+
sprintf('SELECT o, CASE WHEN o.dummyDate IS NULL THEN 0 ELSE 1 END AS HIDDEN _o_dummyDate_null_rank FROM %s o ORDER BY _o_dummyDate_null_rank DESC, o.dummyDate DESC, o.name DESC', Dummy::class),
285+
null,
286+
$orderFilterFactory,
287+
],
268288
'not having order should not throw a deprecation (select unchanged)' => [
269289
sprintf('SELECT o FROM %s o', Dummy::class),
270290
null,

0 commit comments

Comments
 (0)