@@ -4,9 +4,12 @@ use super::{PaginatedModel, DB};
4
4
use crate :: schema:: group_members;
5
5
use crate :: schema:: groups:: dsl;
6
6
use chrono:: NaiveDateTime ;
7
+ use diesel:: debug_query;
7
8
use diesel:: dsl:: count_star;
9
+ use diesel:: pg:: Pg ;
8
10
use diesel:: prelude:: * ;
9
11
use diesel:: { associations:: HasTable , dsl:: not} ;
12
+ use log:: info;
10
13
use serde:: { Deserialize , Serialize } ;
11
14
12
15
#[ derive( diesel_derive_enum:: DbEnum , Debug , Clone , Deserialize , Serialize , PartialEq ) ]
@@ -127,7 +130,7 @@ impl GroupRepository {
127
130
}
128
131
}
129
132
130
- /// Gets all groups a user is member or tutor of
133
+ /// Gets all groups a user is no member or tutor of
131
134
pub fn get_groups_for_not_member (
132
135
member_id : i32 ,
133
136
page : i64 ,
@@ -139,17 +142,21 @@ impl GroupRepository {
139
142
. map ( |x| x. group_id )
140
143
. collect ( ) ;
141
144
142
- let base_predicate = not ( dsl:: tutor
143
- . eq ( member_id)
144
- . or ( dsl:: id. eq_any ( requested) )
145
- . or ( group_members:: dsl:: member_id. eq ( member_id) ) ) ;
145
+ let base_predicate = not ( dsl:: tutor. eq ( member_id) . or ( dsl:: id. eq_any ( requested) ) . or (
146
+ group_members:: dsl:: member_id
147
+ . eq ( member_id)
148
+ . and ( group_members:: dsl:: group_id. is_not_null ( ) ) ,
149
+ ) ) ;
146
150
147
151
let total_base_query = dsl:: groups
148
152
. left_join ( group_members:: dsl:: group_members)
149
153
. select ( count_star ( ) )
150
154
. filter ( base_predicate. clone ( ) )
151
155
. into_boxed ( ) ;
152
156
157
+ let sql_string = debug_query :: < Pg , _ > ( & total_base_query) . to_string ( ) ;
158
+ println ! ( "{}" , sql_string) ;
159
+
153
160
let total = match search. clone ( ) {
154
161
None => total_base_query
155
162
. get_result :: < i64 > ( conn)
@@ -177,7 +184,8 @@ impl GroupRepository {
177
184
. load :: < Group > ( conn) ,
178
185
} ;
179
186
180
- if results. is_err ( ) {
187
+ if let Err ( e) = results {
188
+ info ! ( "Error from database: {}" , e) ;
181
189
return PaginatedModel {
182
190
total : 0 ,
183
191
results : vec ! [ ] ,
0 commit comments