@@ -284,33 +284,33 @@ def negative?
284
284
end
285
285
286
286
def arel_predicate
287
- predicate = attributes . map { |attribute |
287
+ attributes . map { |attribute |
288
288
association = attribute . parent
289
- if negative? && attribute . associated_collection?
290
- query = context . build_correlated_subquery ( association )
291
- context . remove_association ( association )
292
- if self . predicate_name == 'not_null' && self . value
293
- query . where ( format_predicate ( attribute ) )
294
- Arel ::Nodes ::In . new ( context . primary_key , Arel . sql ( query . to_sql ) )
295
- else
296
- query . where ( format_predicate ( attribute ) . not )
297
- Arel ::Nodes ::NotIn . new ( context . primary_key , Arel . sql ( query . to_sql ) )
298
- end
299
- else
300
- format_predicate ( attribute )
289
+ predicate = if negative? && attribute . associated_collection?
290
+ query = context . build_correlated_subquery ( association )
291
+ context . remove_association ( association )
292
+ if self . predicate_name == 'not_null' && self . value
293
+ query . where ( format_predicate ( attribute ) )
294
+ Arel ::Nodes ::In . new ( context . primary_key , Arel . sql ( query . to_sql ) )
295
+ else
296
+ query . where ( format_predicate ( attribute ) . not )
297
+ Arel ::Nodes ::NotIn . new ( context . primary_key , Arel . sql ( query . to_sql ) )
298
+ end
299
+ else
300
+ format_predicate ( attribute )
301
+ end
302
+
303
+ if replace_right_node? ( predicate )
304
+ # Replace right node object to plain integer value in order to avoid
305
+ # ActiveModel::RangeError from Arel::Node::Casted.
306
+ # The error can be ignored here because RDBMSs accept large numbers
307
+ # in condition clauses.
308
+ plain_value = predicate . right . value
309
+ predicate . right = plain_value
301
310
end
302
- } . reduce ( combinator_method )
303
311
304
- if replace_right_node? ( predicate )
305
- # Replace right node object to plain integer value in order to avoid
306
- # ActiveModel::RangeError from Arel::Node::Casted.
307
- # The error can be ignored here because RDBMSs accept large numbers
308
- # in condition clauses.
309
- plain_value = predicate . right . value
310
- predicate . right = plain_value
311
- end
312
-
313
- predicate
312
+ predicate
313
+ } . reduce ( combinator_method )
314
314
end
315
315
316
316
private
0 commit comments