From eb4a623d74fe501ac73dc53d77cfca0d9d4ee01b Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Wed, 12 Sep 2012 23:32:50 +0100 Subject: Fix nested association references Previously the reflection would be looked up on the wrong class. However the test passed because the examples referred back to themselves. --- activerecord/lib/active_record/relation/predicate_builder.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'activerecord/lib/active_record') diff --git a/activerecord/lib/active_record/relation/predicate_builder.rb b/activerecord/lib/active_record/relation/predicate_builder.rb index 593de71fb3..49fbd1686b 100644 --- a/activerecord/lib/active_record/relation/predicate_builder.rb +++ b/activerecord/lib/active_record/relation/predicate_builder.rb @@ -7,10 +7,11 @@ module ActiveRecord table = default_table if value.is_a?(Hash) - table = Arel::Table.new(column, engine) + table = Arel::Table.new(column, engine) + association = engine.reflect_on_association(column.to_sym) - value.each do |k,v| - if rk = find_reflection_key(column, v, v) + value.each do |k, v| + if association && rk = find_reflection_key(k, association.klass, v) if rk[:foreign_type] queries << build(table[rk[:foreign_type]], v.class.base_class) end -- cgit v1.2.3