@@ -3147,8 +3147,7 @@ pub enum ChildKey<'a> {
3147
3147
/// First column is the primary key of the parent
3148
3148
Many ( dsl:: Column < ' a > , Vec < ChildKeyDetails < ' a > > ) ,
3149
3149
Id ( SortDirection , ChildIdDetails < ' a > , UseBlockColumn ) ,
3150
- ManyIdAsc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3151
- ManyIdDesc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3150
+ ManyId ( SortDirection , Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3152
3151
}
3153
3152
3154
3153
/// Convenience to pass the name of the column to order by around. If `name`
@@ -3209,35 +3208,21 @@ impl<'a> fmt::Display for SortKey<'a> {
3209
3208
)
3210
3209
} ) ,
3211
3210
3212
- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: No ) => details
3213
- . iter ( )
3214
- . try_for_each ( |details| write ! ( f, "{}" , details. child_table. primary_key( ) ) ) ,
3215
- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: Yes ) => {
3216
- details. iter ( ) . try_for_each ( |details| {
3217
- write ! (
3218
- f,
3219
- "{}, {}" ,
3220
- details. child_table. primary_key( ) ,
3221
- details. child_table. block_column( )
3222
- )
3223
- } )
3224
- }
3225
- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: No ) => {
3211
+ ChildKey :: ManyId ( direction, details, UseBlockColumn :: No ) => {
3226
3212
details. iter ( ) . try_for_each ( |details| {
3227
- write ! ( f, "{} desc " , details. child_table. primary_key( ) , )
3213
+ write ! ( f, "{}{direction} " , details. child_table. primary_key( ) )
3228
3214
} )
3229
3215
}
3230
- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: Yes ) => {
3216
+ ChildKey :: ManyId ( direction , details, UseBlockColumn :: Yes ) => {
3231
3217
details. iter ( ) . try_for_each ( |details| {
3232
3218
write ! (
3233
3219
f,
3234
- "{} desc , {} desc " ,
3220
+ "{}{direction} , {}{direction} " ,
3235
3221
details. child_table. primary_key( ) ,
3236
- details. child_br
3222
+ details. child_table . block_column ( )
3237
3223
)
3238
3224
} )
3239
3225
}
3240
-
3241
3226
ChildKey :: Id ( direction, details, UseBlockColumn :: No ) => {
3242
3227
write ! ( f, "{}{}" , details. child_table. primary_key( ) , direction)
3243
3228
}
@@ -3506,53 +3491,29 @@ impl<'a> SortKey<'a> {
3506
3491
"Sorting by fulltext fields" . to_string ( ) ,
3507
3492
) )
3508
3493
} else if sort_by_column. is_primary_key ( ) {
3509
- use SortDirection :: * ;
3510
- match direction {
3511
- Asc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdAsc (
3512
- build_children_vec (
3513
- layout,
3514
- block,
3515
- parent_table,
3516
- entity_types,
3517
- child,
3518
- direction,
3519
- ) ?
3520
- . iter ( )
3521
- . map ( |details| ChildIdDetails {
3522
- child_table : details. child_table ,
3523
- child_from : details. child_from ,
3524
- parent_join_column : details. parent_join_column ,
3525
- child_join_column : details. child_join_column ,
3526
- child_pk : details. child_pk ,
3527
- child_br : details. child_br ,
3528
- child_at_block : details. child_at_block ,
3529
- } )
3530
- . collect ( ) ,
3531
- use_block_column,
3532
- ) ) ) ,
3533
- Desc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdDesc (
3534
- build_children_vec (
3535
- layout,
3536
- block,
3537
- parent_table,
3538
- entity_types,
3539
- child,
3540
- direction,
3541
- ) ?
3542
- . iter ( )
3543
- . map ( |details| ChildIdDetails {
3544
- child_table : details. child_table ,
3545
- child_from : details. child_from ,
3546
- parent_join_column : details. parent_join_column ,
3547
- child_join_column : details. child_join_column ,
3548
- child_pk : details. child_pk ,
3549
- child_br : details. child_br ,
3550
- child_at_block : details. child_at_block ,
3551
- } )
3552
- . collect ( ) ,
3553
- use_block_column,
3554
- ) ) ) ,
3555
- }
3494
+ Ok ( SortKey :: ChildKey ( ChildKey :: ManyId (
3495
+ direction,
3496
+ build_children_vec (
3497
+ layout,
3498
+ block,
3499
+ parent_table,
3500
+ entity_types,
3501
+ child,
3502
+ direction,
3503
+ ) ?
3504
+ . iter ( )
3505
+ . map ( |details| ChildIdDetails {
3506
+ child_table : details. child_table ,
3507
+ child_from : details. child_from ,
3508
+ parent_join_column : details. parent_join_column ,
3509
+ child_join_column : details. child_join_column ,
3510
+ child_pk : details. child_pk ,
3511
+ child_br : details. child_br ,
3512
+ child_at_block : details. child_at_block ,
3513
+ } )
3514
+ . collect ( ) ,
3515
+ use_block_column,
3516
+ ) ) )
3556
3517
} else {
3557
3518
Ok ( SortKey :: ChildKey ( ChildKey :: Many (
3558
3519
parent_table. primary_key ( ) ,
@@ -3717,15 +3678,13 @@ impl<'a> SortKey<'a> {
3717
3678
child. sort_by_column . walk_ast ( out. reborrow ( ) ) ?;
3718
3679
}
3719
3680
}
3720
- ChildKey :: ManyIdAsc ( children, UseBlockColumn :: Yes )
3721
- | ChildKey :: ManyIdDesc ( children, UseBlockColumn :: Yes ) => {
3681
+ ChildKey :: ManyId ( _, children, UseBlockColumn :: Yes ) => {
3722
3682
for child in children. iter ( ) {
3723
3683
out. push_sql ( ", " ) ;
3724
3684
child. child_br . walk_ast ( out. reborrow ( ) ) ?;
3725
3685
}
3726
3686
}
3727
- ChildKey :: ManyIdAsc ( _, UseBlockColumn :: No )
3728
- | ChildKey :: ManyIdDesc ( _, UseBlockColumn :: No ) => { /* nothing to do */ }
3687
+ ChildKey :: ManyId ( _, _, UseBlockColumn :: No ) => { /* nothing to do */ }
3729
3688
ChildKey :: Id ( _, child, UseBlockColumn :: Yes ) => {
3730
3689
out. push_sql ( ", " ) ;
3731
3690
child. child_br . walk_ast ( out. reborrow ( ) ) ?;
@@ -3749,7 +3708,6 @@ impl<'a> SortKey<'a> {
3749
3708
out : & mut AstPass < ' _ , ' b , Pg > ,
3750
3709
use_sort_key_alias : bool ,
3751
3710
) -> QueryResult < ( ) > {
3752
- use SortDirection :: * ;
3753
3711
match self {
3754
3712
SortKey :: None => Ok ( ( ) ) ,
3755
3713
SortKey :: Id ( direction, br_column) => {
@@ -3794,11 +3752,8 @@ impl<'a> SortKey<'a> {
3794
3752
out,
3795
3753
) ,
3796
3754
3797
- ChildKey :: ManyIdAsc ( children, use_block_column) => {
3798
- SortKey :: multi_sort_id_expr ( children, Asc , * use_block_column, out)
3799
- }
3800
- ChildKey :: ManyIdDesc ( children, use_block_column) => {
3801
- SortKey :: multi_sort_id_expr ( children, Desc , * use_block_column, out)
3755
+ ChildKey :: ManyId ( direction, children, use_block_column) => {
3756
+ SortKey :: multi_sort_id_expr ( children, * direction, * use_block_column, out)
3802
3757
}
3803
3758
3804
3759
ChildKey :: Id ( direction, child, use_block_column) => {
@@ -4064,7 +4019,7 @@ impl<'a> SortKey<'a> {
4064
4019
) ?;
4065
4020
}
4066
4021
}
4067
- ChildKey :: ManyIdAsc ( children , _ ) | ChildKey :: ManyIdDesc ( children, _) => {
4022
+ ChildKey :: ManyId ( _ , children, _) => {
4068
4023
for child in children. iter ( ) {
4069
4024
add (
4070
4025
& child. child_from ,
0 commit comments