From 0ceb34295501a797c9e549c581ecee17f837f01c Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Tue, 19 Oct 2010 15:24:30 +0100 Subject: Bugfix/refactoring --- activerecord/lib/active_record/reflection.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'activerecord/lib/active_record/reflection.rb') diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb index 6078191773..7ce2bbb8ae 100644 --- a/activerecord/lib/active_record/reflection.rb +++ b/activerecord/lib/active_record/reflection.rb @@ -357,6 +357,8 @@ module ActiveRecord # Holds all the meta-data about a :through association as it was specified # in the Active Record class. class ThroughReflection < AssociationReflection #:nodoc: + delegate :primary_key_name, :association_foreign_key, :to => :source_reflection + # Gets the source of the through reflection. It checks both a singularized # and pluralized form for :belongs_to or :has_many. # @@ -451,6 +453,13 @@ module ActiveRecord def nested? through_reflection_chain.length > 2 end + + # We want to use the klass from this reflection, rather than just delegate straight to + # the source_reflection, because the source_reflection may be polymorphic. We still + # need to respect the source_reflection's :primary_key option, though. + def association_primary_key + @association_primary_key ||= source_reflection.options[:primary_key] || klass.primary_key + end # Gets an array of possible :through source reflection names: # -- cgit v1.2.3