aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/reflection.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2010-10-19 15:24:30 +0100
committerJon Leighton <j@jonathanleighton.com>2010-10-19 15:24:30 +0100
commit0ceb34295501a797c9e549c581ecee17f837f01c (patch)
tree99ba5d6e32716b6539decfa987c546166c32a354 /activerecord/lib/active_record/reflection.rb
parent9ff5fdeda99b3d8c5148d4c40956842518d1c788 (diff)
downloadrails-0ceb34295501a797c9e549c581ecee17f837f01c.tar.gz
rails-0ceb34295501a797c9e549c581ecee17f837f01c.tar.bz2
rails-0ceb34295501a797c9e549c581ecee17f837f01c.zip
Bugfix/refactoring
Diffstat (limited to 'activerecord/lib/active_record/reflection.rb')
-rw-r--r--activerecord/lib/active_record/reflection.rb9
1 files changed, 9 insertions, 0 deletions
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 <tt>:belongs_to</tt> or <tt>:has_many</tt>.
#
@@ -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 <tt>:through</tt> source reflection names:
#