diff options
author | Jon Leighton <j@jonathanleighton.com> | 2010-10-12 18:16:31 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2010-10-12 18:16:31 +0100 |
commit | c37a5e7acde436b359043a67b7daace8be6f08c6 (patch) | |
tree | dc89f219e6aa0be327a35c921ed8b9f005882902 /activerecord/lib | |
parent | 56064aa4b014233ae54413628679b7f7fa5d6f77 (diff) | |
download | rails-c37a5e7acde436b359043a67b7daace8be6f08c6.tar.gz rails-c37a5e7acde436b359043a67b7daace8be6f08c6.tar.bz2 rails-c37a5e7acde436b359043a67b7daace8be6f08c6.zip |
Add a commented, failing test for using a habtm in a has many through association. I want to refactor how aliasing works first.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/associations/through_association_scope.rb | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/activerecord/lib/active_record/associations/through_association_scope.rb b/activerecord/lib/active_record/associations/through_association_scope.rb index 09f92332cf..8c5b95439e 100644 --- a/activerecord/lib/active_record/associations/through_association_scope.rb +++ b/activerecord/lib/active_record/associations/through_association_scope.rb @@ -65,52 +65,56 @@ module ActiveRecord @reflection.through_reflection_chain.each_cons(2) do |left, right| polymorphic_join = nil - case - when left.source_reflection.nil? - # TODO: Perhaps need to pay attention to left.options[:primary_key] and - # left.options[:foreign_key] in places here - - case left.macro - when :belongs_to - left_primary_key = left.klass.primary_key - right_primary_key = left.primary_key_name - when :has_many, :has_one - left_primary_key = left.primary_key_name - right_primary_key = right.klass.primary_key - - if left.options[:as] - polymorphic_join = "AND %s.%s = %s" % [ - table_aliases[left], "#{left.options[:as]}_type", - # TODO: Why right.klass.name? Rather than left.active_record.name? - # TODO: Also should maybe use the base_class (see related code in JoinAssociation) - @owner.class.quote_value(right.klass.name) - ] - end - when :has_and_belongs_to_many - raise NotImplementedError - end - when left.source_reflection.macro == :belongs_to - left_primary_key = left.klass.primary_key - right_primary_key = left.source_reflection.primary_key_name - - if left.options[:source_type] - polymorphic_join = "AND %s.%s = %s" % [ - table_aliases[right], - left.source_reflection.options[:foreign_type].to_s, - @owner.class.quote_value(left.options[:source_type]) - ] - end - else - left_primary_key = left.source_reflection.primary_key_name - right_primary_key = right.klass.primary_key - - if left.source_reflection.options[:as] - polymorphic_join = "AND %s.%s = %s" % [ - table_aliases[left], - "#{left.source_reflection.options[:as]}_type", - @owner.class.quote_value(right.klass.name) - ] - end + if left.source_reflection.nil? + # TODO: Perhaps need to pay attention to left.options[:primary_key] and + # left.options[:foreign_key] in places here + + case left.macro + when :belongs_to + left_primary_key = left.klass.primary_key + right_primary_key = left.primary_key_name + when :has_many, :has_one + left_primary_key = left.primary_key_name + right_primary_key = right.klass.primary_key + + if left.options[:as] + polymorphic_join = "AND %s.%s = %s" % [ + table_aliases[left], "#{left.options[:as]}_type", + # TODO: Why right.klass.name? Rather than left.active_record.name? + # TODO: Also should maybe use the base_class (see related code in JoinAssociation) + @owner.class.quote_value(right.klass.name) + ] + end + when :has_and_belongs_to_many + raise NotImplementedError + end + else + case left.source_reflection.macro + when :belongs_to + left_primary_key = left.klass.primary_key + right_primary_key = left.source_reflection.primary_key_name + + if left.options[:source_type] + polymorphic_join = "AND %s.%s = %s" % [ + table_aliases[right], + left.source_reflection.options[:foreign_type].to_s, + @owner.class.quote_value(left.options[:source_type]) + ] + end + when :has_many, :has_one + left_primary_key = left.source_reflection.primary_key_name + right_primary_key = right.klass.primary_key + + if left.source_reflection.options[:as] + polymorphic_join = "AND %s.%s = %s" % [ + table_aliases[left], + "#{left.source_reflection.options[:as]}_type", + @owner.class.quote_value(right.klass.name) + ] + end + when :has_and_belongs_to_many + raise NotImplementedError + end end if right.quoted_table_name == table_aliases[right] |