Permalink
Browse files

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.
  • Loading branch information...
1 parent 13c0d8c commit 4095c08729a188e6ebc24f86d60a10bc01053d9b @carlosantoniodasilva carlosantoniodasilva committed Jan 17, 2013
Showing with 4 additions and 4 deletions.
  1. +4 −4 activerecord/lib/active_record/relation/predicate_builder.rb
@@ -7,12 +7,12 @@ def self.build_from_hash(klass, attributes, default_table)
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

0 comments on commit 4095c08

Please sign in to comment.