@@ -3140,8 +3140,7 @@ pub enum ChildKey<'a> {
31403140 /// First column is the primary key of the parent
31413141 Many ( dsl:: Column < ' a > , Vec < ChildKeyDetails < ' a > > ) ,
31423142 Id ( SortDirection , ChildIdDetails < ' a > , UseBlockColumn ) ,
3143- ManyIdAsc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3144- ManyIdDesc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3143+ ManyId ( SortDirection , Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
31453144}
31463145
31473146/// Convenience to pass the name of the column to order by around. If `name`
@@ -3202,35 +3201,21 @@ impl<'a> fmt::Display for SortKey<'a> {
32023201 )
32033202 } ) ,
32043203
3205- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: No ) => details
3206- . iter ( )
3207- . try_for_each ( |details| write ! ( f, "{}" , details. child_table. primary_key( ) ) ) ,
3208- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: Yes ) => {
3209- details. iter ( ) . try_for_each ( |details| {
3210- write ! (
3211- f,
3212- "{}, {}" ,
3213- details. child_table. primary_key( ) ,
3214- details. child_table. block_column( )
3215- )
3216- } )
3217- }
3218- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: No ) => {
3204+ ChildKey :: ManyId ( direction, details, UseBlockColumn :: No ) => {
32193205 details. iter ( ) . try_for_each ( |details| {
3220- write ! ( f, "{} desc " , details. child_table. primary_key( ) , )
3206+ write ! ( f, "{}{direction} " , details. child_table. primary_key( ) )
32213207 } )
32223208 }
3223- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: Yes ) => {
3209+ ChildKey :: ManyId ( direction , details, UseBlockColumn :: Yes ) => {
32243210 details. iter ( ) . try_for_each ( |details| {
32253211 write ! (
32263212 f,
3227- "{} desc , {} desc " ,
3213+ "{}{direction} , {}{direction} " ,
32283214 details. child_table. primary_key( ) ,
3229- details. child_br
3215+ details. child_table . block_column ( )
32303216 )
32313217 } )
32323218 }
3233-
32343219 ChildKey :: Id ( direction, details, UseBlockColumn :: No ) => {
32353220 write ! ( f, "{}{}" , details. child_table. primary_key( ) , direction)
32363221 }
@@ -3499,53 +3484,29 @@ impl<'a> SortKey<'a> {
34993484 "Sorting by fulltext fields" . to_string ( ) ,
35003485 ) )
35013486 } else if sort_by_column. is_primary_key ( ) {
3502- use SortDirection :: * ;
3503- match direction {
3504- Asc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdAsc (
3505- build_children_vec (
3506- layout,
3507- block,
3508- parent_table,
3509- entity_types,
3510- child,
3511- direction,
3512- ) ?
3513- . iter ( )
3514- . map ( |details| ChildIdDetails {
3515- child_table : details. child_table ,
3516- child_from : details. child_from ,
3517- parent_join_column : details. parent_join_column ,
3518- child_join_column : details. child_join_column ,
3519- child_pk : details. child_pk ,
3520- child_br : details. child_br ,
3521- child_at_block : details. child_at_block ,
3522- } )
3523- . collect ( ) ,
3524- use_block_column,
3525- ) ) ) ,
3526- Desc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdDesc (
3527- build_children_vec (
3528- layout,
3529- block,
3530- parent_table,
3531- entity_types,
3532- child,
3533- direction,
3534- ) ?
3535- . iter ( )
3536- . map ( |details| ChildIdDetails {
3537- child_table : details. child_table ,
3538- child_from : details. child_from ,
3539- parent_join_column : details. parent_join_column ,
3540- child_join_column : details. child_join_column ,
3541- child_pk : details. child_pk ,
3542- child_br : details. child_br ,
3543- child_at_block : details. child_at_block ,
3544- } )
3545- . collect ( ) ,
3546- use_block_column,
3547- ) ) ) ,
3548- }
3487+ Ok ( SortKey :: ChildKey ( ChildKey :: ManyId (
3488+ direction,
3489+ build_children_vec (
3490+ layout,
3491+ block,
3492+ parent_table,
3493+ entity_types,
3494+ child,
3495+ direction,
3496+ ) ?
3497+ . iter ( )
3498+ . map ( |details| ChildIdDetails {
3499+ child_table : details. child_table ,
3500+ child_from : details. child_from ,
3501+ parent_join_column : details. parent_join_column ,
3502+ child_join_column : details. child_join_column ,
3503+ child_pk : details. child_pk ,
3504+ child_br : details. child_br ,
3505+ child_at_block : details. child_at_block ,
3506+ } )
3507+ . collect ( ) ,
3508+ use_block_column,
3509+ ) ) )
35493510 } else {
35503511 Ok ( SortKey :: ChildKey ( ChildKey :: Many (
35513512 parent_table. primary_key ( ) ,
@@ -3710,15 +3671,13 @@ impl<'a> SortKey<'a> {
37103671 child. sort_by_column . walk_ast ( out. reborrow ( ) ) ?;
37113672 }
37123673 }
3713- ChildKey :: ManyIdAsc ( children, UseBlockColumn :: Yes )
3714- | ChildKey :: ManyIdDesc ( children, UseBlockColumn :: Yes ) => {
3674+ ChildKey :: ManyId ( _, children, UseBlockColumn :: Yes ) => {
37153675 for child in children. iter ( ) {
37163676 out. push_sql ( ", " ) ;
37173677 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
37183678 }
37193679 }
3720- ChildKey :: ManyIdAsc ( _, UseBlockColumn :: No )
3721- | ChildKey :: ManyIdDesc ( _, UseBlockColumn :: No ) => { /* nothing to do */ }
3680+ ChildKey :: ManyId ( _, _, UseBlockColumn :: No ) => { /* nothing to do */ }
37223681 ChildKey :: Id ( _, child, UseBlockColumn :: Yes ) => {
37233682 out. push_sql ( ", " ) ;
37243683 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
@@ -3742,7 +3701,6 @@ impl<'a> SortKey<'a> {
37423701 out : & mut AstPass < ' _ , ' b , Pg > ,
37433702 use_sort_key_alias : bool ,
37443703 ) -> QueryResult < ( ) > {
3745- use SortDirection :: * ;
37463704 match self {
37473705 SortKey :: None => Ok ( ( ) ) ,
37483706 SortKey :: Id ( direction, br_column) => {
@@ -3787,11 +3745,8 @@ impl<'a> SortKey<'a> {
37873745 out,
37883746 ) ,
37893747
3790- ChildKey :: ManyIdAsc ( children, use_block_column) => {
3791- SortKey :: multi_sort_id_expr ( children, Asc , * use_block_column, out)
3792- }
3793- ChildKey :: ManyIdDesc ( children, use_block_column) => {
3794- SortKey :: multi_sort_id_expr ( children, Desc , * use_block_column, out)
3748+ ChildKey :: ManyId ( direction, children, use_block_column) => {
3749+ SortKey :: multi_sort_id_expr ( children, * direction, * use_block_column, out)
37953750 }
37963751
37973752 ChildKey :: Id ( direction, child, use_block_column) => {
@@ -4057,7 +4012,7 @@ impl<'a> SortKey<'a> {
40574012 ) ?;
40584013 }
40594014 }
4060- ChildKey :: ManyIdAsc ( children , _ ) | ChildKey :: ManyIdDesc ( children, _) => {
4015+ ChildKey :: ManyId ( _ , children, _) => {
40614016 for child in children. iter ( ) {
40624017 add (
40634018 & child. child_from ,
0 commit comments