@@ -3146,8 +3146,7 @@ pub enum ChildKey<'a> {
31463146 /// First column is the primary key of the parent
31473147 Many ( dsl:: Column < ' a > , Vec < ChildKeyDetails < ' a > > ) ,
31483148 Id ( SortDirection , ChildIdDetails < ' a > , UseBlockColumn ) ,
3149- ManyIdAsc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3150- ManyIdDesc ( Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
3149+ ManyId ( SortDirection , Vec < ChildIdDetails < ' a > > , UseBlockColumn ) ,
31513150}
31523151
31533152/// Convenience to pass the name of the column to order by around. If `name`
@@ -3208,35 +3207,21 @@ impl<'a> fmt::Display for SortKey<'a> {
32083207 )
32093208 } ) ,
32103209
3211- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: No ) => details
3212- . iter ( )
3213- . try_for_each ( |details| write ! ( f, "{}" , details. child_table. primary_key( ) ) ) ,
3214- ChildKey :: ManyIdAsc ( details, UseBlockColumn :: Yes ) => {
3215- details. iter ( ) . try_for_each ( |details| {
3216- write ! (
3217- f,
3218- "{}, {}" ,
3219- details. child_table. primary_key( ) ,
3220- details. child_table. block_column( )
3221- )
3222- } )
3223- }
3224- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: No ) => {
3210+ ChildKey :: ManyId ( direction, details, UseBlockColumn :: No ) => {
32253211 details. iter ( ) . try_for_each ( |details| {
3226- write ! ( f, "{} desc " , details. child_table. primary_key( ) , )
3212+ write ! ( f, "{}{direction} " , details. child_table. primary_key( ) )
32273213 } )
32283214 }
3229- ChildKey :: ManyIdDesc ( details, UseBlockColumn :: Yes ) => {
3215+ ChildKey :: ManyId ( direction , details, UseBlockColumn :: Yes ) => {
32303216 details. iter ( ) . try_for_each ( |details| {
32313217 write ! (
32323218 f,
3233- "{} desc , {} desc " ,
3219+ "{}{direction} , {}{direction} " ,
32343220 details. child_table. primary_key( ) ,
3235- details. child_br
3221+ details. child_table . block_column ( )
32363222 )
32373223 } )
32383224 }
3239-
32403225 ChildKey :: Id ( direction, details, UseBlockColumn :: No ) => {
32413226 write ! ( f, "{}{}" , details. child_table. primary_key( ) , direction)
32423227 }
@@ -3505,53 +3490,29 @@ impl<'a> SortKey<'a> {
35053490 "Sorting by fulltext fields" . to_string ( ) ,
35063491 ) )
35073492 } else if sort_by_column. is_primary_key ( ) {
3508- use SortDirection :: * ;
3509- match direction {
3510- Asc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdAsc (
3511- build_children_vec (
3512- layout,
3513- block,
3514- parent_table,
3515- entity_types,
3516- child,
3517- direction,
3518- ) ?
3519- . iter ( )
3520- . map ( |details| ChildIdDetails {
3521- child_table : details. child_table ,
3522- child_from : details. child_from ,
3523- parent_join_column : details. parent_join_column ,
3524- child_join_column : details. child_join_column ,
3525- child_pk : details. child_pk ,
3526- child_br : details. child_br ,
3527- child_at_block : details. child_at_block ,
3528- } )
3529- . collect ( ) ,
3530- use_block_column,
3531- ) ) ) ,
3532- Desc => Ok ( SortKey :: ChildKey ( ChildKey :: ManyIdDesc (
3533- build_children_vec (
3534- layout,
3535- block,
3536- parent_table,
3537- entity_types,
3538- child,
3539- direction,
3540- ) ?
3541- . iter ( )
3542- . map ( |details| ChildIdDetails {
3543- child_table : details. child_table ,
3544- child_from : details. child_from ,
3545- parent_join_column : details. parent_join_column ,
3546- child_join_column : details. child_join_column ,
3547- child_pk : details. child_pk ,
3548- child_br : details. child_br ,
3549- child_at_block : details. child_at_block ,
3550- } )
3551- . collect ( ) ,
3552- use_block_column,
3553- ) ) ) ,
3554- }
3493+ Ok ( SortKey :: ChildKey ( ChildKey :: ManyId (
3494+ direction,
3495+ build_children_vec (
3496+ layout,
3497+ block,
3498+ parent_table,
3499+ entity_types,
3500+ child,
3501+ direction,
3502+ ) ?
3503+ . iter ( )
3504+ . map ( |details| ChildIdDetails {
3505+ child_table : details. child_table ,
3506+ child_from : details. child_from ,
3507+ parent_join_column : details. parent_join_column ,
3508+ child_join_column : details. child_join_column ,
3509+ child_pk : details. child_pk ,
3510+ child_br : details. child_br ,
3511+ child_at_block : details. child_at_block ,
3512+ } )
3513+ . collect ( ) ,
3514+ use_block_column,
3515+ ) ) )
35553516 } else {
35563517 Ok ( SortKey :: ChildKey ( ChildKey :: Many (
35573518 parent_table. primary_key ( ) ,
@@ -3716,15 +3677,13 @@ impl<'a> SortKey<'a> {
37163677 child. sort_by_column . walk_ast ( out. reborrow ( ) ) ?;
37173678 }
37183679 }
3719- ChildKey :: ManyIdAsc ( children, UseBlockColumn :: Yes )
3720- | ChildKey :: ManyIdDesc ( children, UseBlockColumn :: Yes ) => {
3680+ ChildKey :: ManyId ( _, children, UseBlockColumn :: Yes ) => {
37213681 for child in children. iter ( ) {
37223682 out. push_sql ( ", " ) ;
37233683 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
37243684 }
37253685 }
3726- ChildKey :: ManyIdAsc ( _, UseBlockColumn :: No )
3727- | ChildKey :: ManyIdDesc ( _, UseBlockColumn :: No ) => { /* nothing to do */ }
3686+ ChildKey :: ManyId ( _, _, UseBlockColumn :: No ) => { /* nothing to do */ }
37283687 ChildKey :: Id ( _, child, UseBlockColumn :: Yes ) => {
37293688 out. push_sql ( ", " ) ;
37303689 child. child_br . walk_ast ( out. reborrow ( ) ) ?;
@@ -3748,7 +3707,6 @@ impl<'a> SortKey<'a> {
37483707 out : & mut AstPass < ' _ , ' b , Pg > ,
37493708 use_sort_key_alias : bool ,
37503709 ) -> QueryResult < ( ) > {
3751- use SortDirection :: * ;
37523710 match self {
37533711 SortKey :: None => Ok ( ( ) ) ,
37543712 SortKey :: Id ( direction, br_column) => {
@@ -3793,11 +3751,8 @@ impl<'a> SortKey<'a> {
37933751 out,
37943752 ) ,
37953753
3796- ChildKey :: ManyIdAsc ( children, use_block_column) => {
3797- SortKey :: multi_sort_id_expr ( children, Asc , * use_block_column, out)
3798- }
3799- ChildKey :: ManyIdDesc ( children, use_block_column) => {
3800- SortKey :: multi_sort_id_expr ( children, Desc , * use_block_column, out)
3754+ ChildKey :: ManyId ( direction, children, use_block_column) => {
3755+ SortKey :: multi_sort_id_expr ( children, * direction, * use_block_column, out)
38013756 }
38023757
38033758 ChildKey :: Id ( direction, child, use_block_column) => {
@@ -4063,7 +4018,7 @@ impl<'a> SortKey<'a> {
40634018 ) ?;
40644019 }
40654020 }
4066- ChildKey :: ManyIdAsc ( children , _ ) | ChildKey :: ManyIdDesc ( children, _) => {
4021+ ChildKey :: ManyId ( _ , children, _) => {
40674022 for child in children. iter ( ) {
40684023 add (
40694024 & child. child_from ,
0 commit comments