diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-05-16 17:07:21 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-05-22 21:25:02 +0100 |
commit | d7a910e31e839e5544aa9f83f9922ecfcee74ed5 (patch) | |
tree | e27b725c1805246b2dd07aabec5fda5caf8d259e /activerecord/lib/active_record/associations/join_dependency | |
parent | 8c19ebe5539fae896a1a6fb2549e9e63445b6607 (diff) | |
download | rails-d7a910e31e839e5544aa9f83f9922ecfcee74ed5.tar.gz rails-d7a910e31e839e5544aa9f83f9922ecfcee74ed5.tar.bz2 rails-d7a910e31e839e5544aa9f83f9922ecfcee74ed5.zip |
Fix problem with loading polymorphic associations which have been defined in an abstract superclass. Fixes #552.
Diffstat (limited to 'activerecord/lib/active_record/associations/join_dependency')
-rw-r--r-- | activerecord/lib/active_record/associations/join_dependency/join_association.rb | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/activerecord/lib/active_record/associations/join_dependency/join_association.rb b/activerecord/lib/active_record/associations/join_dependency/join_association.rb index c32753782f..03963ab060 100644 --- a/activerecord/lib/active_record/associations/join_dependency/join_association.rb +++ b/activerecord/lib/active_record/associations/join_dependency/join_association.rb @@ -62,6 +62,7 @@ module ActiveRecord def join_to(relation) tables = @tables.dup foreign_table = parent_table + foreign_klass = parent.active_record # The chain starts with the target table, but we want to end with it here (makes # more sense in this context), so we reverse @@ -91,14 +92,17 @@ module ActiveRecord constraint = build_constraint(reflection, table, key, foreign_table, foreign_key) - unless conditions[i].empty? - constraint = constraint.and(sanitize(conditions[i], table)) + conditions = self.conditions[i].dup + conditions << { reflection.type => foreign_klass.base_class.name } if reflection.type + + unless conditions.empty? + constraint = constraint.and(sanitize(conditions, table)) end relation.from(join(table, constraint)) # The current table in this iteration becomes the foreign table in the next - foreign_table = table + foreign_table, foreign_klass = table, reflection.klass end relation |