Permalink
Browse files

Pass in the model class rather than engine

In some circumstances engine was Arel::Table.engine which for separate
reasons was an ActiveRecord::Model::DeprecationProxy, which caused a
deprecation warning.

In any case, we want the actual model class here, since we want to use
it to infer information about associations.
  • Loading branch information...
1 parent e588c98 commit e55c75d2d8c137a2482fb6464953801e69b6e335 @jonleighton jonleighton committed Sep 12, 2012
@@ -1,14 +1,14 @@
module ActiveRecord
class PredicateBuilder # :nodoc:
- def self.build_from_hash(engine, attributes, default_table)
+ def self.build_from_hash(klass, attributes, default_table)
queries = []
attributes.each do |column, value|
table = default_table
if value.is_a?(Hash)
- table = Arel::Table.new(column, engine)
- association = engine.reflect_on_association(column.to_sym)
+ 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)
@@ -18,10 +18,10 @@ def self.build_from_hash(engine, attributes, default_table)
if column.include?('.')
table_name, column = column.split('.', 2)
- table = Arel::Table.new(table_name, engine)
+ table = Arel::Table.new(table_name, default_table.engine)
end
- queries.concat expand(engine, table, column, value)
+ queries.concat expand(klass, table, column, value)
end
end
@@ -708,7 +708,7 @@ def build_where(opts, other = [])
[@klass.send(:sanitize_sql, other.empty? ? opts : ([opts] + other))]
when Hash
attributes = @klass.send(:expand_hash_conditions_for_aggregates, opts)
- PredicateBuilder.build_from_hash(table.engine, attributes, table)
+ PredicateBuilder.build_from_hash(klass, attributes, table)
else
[opts]
end
@@ -88,8 +88,8 @@ def expand_hash_conditions_for_aggregates(attrs)
def sanitize_sql_hash_for_conditions(attrs, default_table_name = self.table_name)
attrs = expand_hash_conditions_for_aggregates(attrs)
- table = Arel::Table.new(table_name).alias(default_table_name)
- PredicateBuilder.build_from_hash(arel_engine, attrs, table).map { |b|
+ table = Arel::Table.new(table_name, arel_engine).alias(default_table_name)
+ PredicateBuilder.build_from_hash(self.class, attrs, table).map { |b|
connection.visitor.accept b
}.join(' AND ')
end

0 comments on commit e55c75d

Please sign in to comment.