@@ -3147,8 +3147,7 @@ pub enum ChildKey<'a> {
31473147 /// First column is the primary key of the parent
31483148 Many ( dsl:: Column < ' a > , Vec < ChildKeyDetails < ' a > > ) ,
31493149 Id ( SortDirection , ChildIdDetails < ' a > , UseBlockColumn ) ,
3150- ManyIdAsc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3151- ManyIdDesc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3150+ ManyId ( SortDirection , Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
31523151}
31533152
31543153/// 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> {
32093208 )
32103209 } ) ,
32113210
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 ) => {
32263212 details. iter ( ) . try_for_each ( |details| {
3227- write ! ( f, "{} desc " , details. child_table. primary_key( ) , )
3213+ write ! ( f, "{}{direction} " , details. child_table. primary_key( ) )
32283214 } )
32293215 }
3230- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: Yes ) => {
3216+ ChildKey :: ManyId ( direction , details, UseBlockColumn :: Yes ) => {
32313217 details. iter ( ) . try_for_each ( |details| {
32323218 write ! (
32333219 f,
3234- "{} desc , {} desc " ,
3220+ "{}{direction} , {}{direction} " ,
32353221 details. child_table. primary_key( ) ,
3236- details. child_br
3222+ details. child_table . block_column ( )
32373223 )
32383224 } )
32393225 }
3240-
32413226 ChildKey :: Id ( direction, details, UseBlockColumn :: No ) => {
32423227 write ! ( f, "{}{}" , details. child_table. primary_key( ) , direction)
32433228 }
@@ -3506,53 +3491,29 @@ impl<'a> SortKey<'a> {
35063491 "Sorting by fulltext fields" . to_string ( ) ,
35073492 ) )
35083493 } 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+ ) ) )
35563517 } else {
35573518 Ok ( SortKey :: ChildKey ( ChildKey :: Many (
35583519 parent_table. primary_key ( ) ,
@@ -3717,15 +3678,13 @@ impl<'a> SortKey<'a> {
37173678 child. sort_by_column . walk_ast ( out. reborrow ( ) ) ?;
37183679 }
37193680 }
3720- ChildKey :: ManyIdAsc ( children, UseBlockColumn :: Yes )
3721- | ChildKey :: ManyIdDesc ( children, UseBlockColumn :: Yes ) => {
3681+ ChildKey :: ManyId ( _, children, UseBlockColumn :: Yes ) => {
37223682 for child in children. iter ( ) {
37233683 out. push_sql ( ", " ) ;
37243684 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
37253685 }
37263686 }
3727- ChildKey :: ManyIdAsc ( _, UseBlockColumn :: No )
3728- | ChildKey :: ManyIdDesc ( _, UseBlockColumn :: No ) => { /* nothing to do */ }
3687+ ChildKey :: ManyId ( _, _, UseBlockColumn :: No ) => { /* nothing to do */ }
37293688 ChildKey :: Id ( _, child, UseBlockColumn :: Yes ) => {
37303689 out. push_sql ( ", " ) ;
37313690 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
@@ -3749,7 +3708,6 @@ impl<'a> SortKey<'a> {
37493708 out : & mut AstPass < ' _ , ' b , Pg > ,
37503709 use_sort_key_alias : bool ,
37513710 ) -> QueryResult < ( ) > {
3752- use SortDirection :: * ;
37533711 match self {
37543712 SortKey :: None => Ok ( ( ) ) ,
37553713 SortKey :: Id ( direction, br_column) => {
@@ -3794,11 +3752,8 @@ impl<'a> SortKey<'a> {
37943752 out,
37953753 ) ,
37963754
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)
38023757 }
38033758
38043759 ChildKey :: Id ( direction, child, use_block_column) => {
@@ -4064,7 +4019,7 @@ impl<'a> SortKey<'a> {
40644019 ) ?;
40654020 }
40664021 }
4067- ChildKey :: ManyIdAsc ( children , _ ) | ChildKey :: ManyIdDesc ( children, _) => {
4022+ ChildKey :: ManyId ( _ , children, _) => {
40684023 for child in children. iter ( ) {
40694024 add (
40704025 & child. child_from ,
0 commit comments