aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2012-09-12 23:32:50 +0100
committerJon Leighton <j@jonathanleighton.com>2012-09-12 23:32:50 +0100
commiteb4a623d74fe501ac73dc53d77cfca0d9d4ee01b (patch)
tree64e95beb96dc293aa3b5f277b05de58453f9e7cd /activerecord/lib/active_record
parentb5aed34c442550c4caad1fdca12c921d5ab9840f (diff)
downloadrails-eb4a623d74fe501ac73dc53d77cfca0d9d4ee01b.tar.gz
rails-eb4a623d74fe501ac73dc53d77cfca0d9d4ee01b.tar.bz2
rails-eb4a623d74fe501ac73dc53d77cfca0d9d4ee01b.zip
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.
Diffstat (limited to 'activerecord/lib/active_record')
-rw-r--r--activerecord/lib/active_record/relation/predicate_builder.rb7
1 files changed, 4 insertions, 3 deletions
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