aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib
diff options
context:
space:
mode:
authorCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-17 21:09:43 -0200
committerCarlos Antonio da Silva <carlosantoniodasilva@gmail.com>2013-01-17 21:12:44 -0200
commit4095c08729a188e6ebc24f86d60a10bc01053d9b (patch)
tree134a78021c17392eeac645ec4a30119be0e0e84a /activerecord/lib
parent13c0d8c5b31a308b45d8f053df48163cf1d308b5 (diff)
downloadrails-4095c08729a188e6ebc24f86d60a10bc01053d9b.tar.gz
rails-4095c08729a188e6ebc24f86d60a10bc01053d9b.tar.bz2
rails-4095c08729a188e6ebc24f86d60a10bc01053d9b.zip
Refactor predicate builder when receiving empty hash
There's no need to create a new arel table or reflect on the column association if the value is empty, these attributes are not used. Also no need to concat a new array, just append the query value.
Diffstat (limited to 'activerecord/lib')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb8
1 files changed, 4 insertions, 4 deletions
diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb
index 83074e72c1..883d25d80b 100644
--- a/activerecord/lib/active_record/relation/predicate_builder.rb
+++ b/activerecord/lib/active_record/relation/predicate_builder.rb
@@ -7,12 +7,12 @@ module ActiveRecord
table = default_table
if value.is_a?(Hash)
- table = Arel::Table.new(column, default_table.engine)
- association = klass.reflect_on_association(column.to_sym)
-
if value.empty?
- queries.concat ['1 = 2']
+ queries << '1 = 2'
else
+ table = Arel::Table.new(column, default_table.engine)
+ association = klass.reflect_on_association(column.to_sym)
+
value.each do |k, v|
queries.concat expand(association && association.klass, table, k, v)
end