@@ -59,6 +59,37 @@ fn simple_having_with_group_by() {
5959 assert_eq ! ( expected_data, data) ;
6060}
6161
62+ #[ test]
63+ fn boxed_simple_having_with_group_by ( ) {
64+ let connection = connection ( ) ;
65+ connection
66+ . execute ( "INSERT INTO users (id, name) VALUES (1, 'Sean'), (2, 'Tess')" )
67+ . unwrap ( ) ;
68+ connection
69+ . execute (
70+ "INSERT INTO posts (id, user_id, title) VALUES (1, 1, 'Hi Sean'), (2, 2, 'Hi Tess')" ,
71+ )
72+ . unwrap ( ) ;
73+ connection
74+ . execute (
75+ "INSERT INTO comments (id, post_id, text) VALUES (1, 1, 'Comment for Hi Sean'), \
76+ (2, 2, 'Comment for Hi Tess'), (3, 2, 'Another comment for Hi Tess')",
77+ )
78+ . unwrap ( ) ;
79+
80+ let source = users:: table
81+ . inner_join ( posts:: table. inner_join ( comments:: table) )
82+ . group_by ( ( users:: id, posts:: id) )
83+ . having ( diesel:: dsl:: count ( comments:: id) . eq ( 2 ) )
84+ . select ( ( users:: name, posts:: title) )
85+ . into_boxed ( ) ;
86+
87+ let expected_data = vec ! [ ( "Tess" . to_string( ) , "Hi Tess" . to_string( ) ) ] ;
88+ let data: Vec < ( String , String ) > = source. load ( & connection) . unwrap ( ) ;
89+
90+ assert_eq ! ( expected_data, data) ;
91+ }
92+
6293#[ test]
6394fn multi_condition_having_with_group_by ( ) {
6495 let connection = connection ( ) ;
@@ -89,3 +120,35 @@ fn multi_condition_having_with_group_by() {
89120
90121 assert_eq ! ( expected_data, data) ;
91122}
123+
124+ #[ test]
125+ fn boxed_multi_condition_having_with_group_by ( ) {
126+ let connection = connection ( ) ;
127+ connection
128+ . execute ( "INSERT INTO users (id, name) VALUES (1, 'Sean'), (2, 'Tess'), (3, 'Nick')" )
129+ . unwrap ( ) ;
130+ connection
131+ . execute (
132+ "INSERT INTO posts (id, user_id, title) VALUES (1, 1, 'Hi Sean'), (2, 2, 'Hi Tess'), (3, 3, 'Hi Nick')" ,
133+ )
134+ . unwrap ( ) ;
135+ connection
136+ . execute (
137+ "INSERT INTO comments (id, post_id, text) VALUES (1, 1, 'Comment for Hi Sean'), \
138+ (2, 2, 'Comment for Hi Tess'), (3, 2, 'Another comment for Hi Tess'), \
139+ (4, 3, 'Comment for Hi Nick'), (5, 3, 'Another comment for Hi Nick')",
140+ )
141+ . unwrap ( ) ;
142+
143+ let source = users:: table
144+ . inner_join ( posts:: table. inner_join ( comments:: table) )
145+ . group_by ( ( users:: id, posts:: id) )
146+ . having ( diesel:: dsl:: count ( comments:: id) . eq ( 2 ) . and ( users:: id. eq ( 3 ) ) )
147+ . select ( ( users:: id, users:: name, posts:: title) )
148+ . into_boxed ( ) ;
149+
150+ let expected_data = vec ! [ ( 3 , "Nick" . to_string( ) , "Hi Nick" . to_string( ) ) ] ;
151+ let data: Vec < ( i32 , String , String ) > = source. load ( & connection) . unwrap ( ) ;
152+
153+ assert_eq ! ( expected_data, data) ;
154+ }
0 commit comments