mirror of https://github.com/rails/rails
Remove useless branch for the array predicate handler
The array predicate handler don't generate `IN` clause if the values has
only one element.
4ef77ac8de/activerecord/lib/active_record/relation/predicate_builder/array_handler.rb (L22)
Also, I've refactored to avoid extra spawn by `where.not` and directly
mutate `self.where_clause`.
This commit is contained in:
parent
4ef77ac8de
commit
c6f0861515
|
@ -1146,13 +1146,9 @@ module ActiveRecord
|
|||
end
|
||||
|
||||
def excluding!(records) # :nodoc:
|
||||
# Treat single and multiple records differently in order to keep query
|
||||
# clean in case of single record, ie, use != operator instead of NOT IN ().
|
||||
if records.one?
|
||||
where.not(primary_key => records.first.id)
|
||||
else
|
||||
where.not(primary_key => records)
|
||||
end
|
||||
predicates = [ predicate_builder[primary_key, records].invert ]
|
||||
self.where_clause += Relation::WhereClause.new(predicates)
|
||||
self
|
||||
end
|
||||
|
||||
# Returns the Arel object associated with the relation.
|
||||
|
|
Loading…
Reference in New Issue