aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/association_scope.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-26 15:41:31 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-26 15:42:34 +0100
commit3b87c38d029c1626161a3e7699d40da3e789d7cb (patch)
treeb056af6ff031bf5ee83e9d8a25307ae72668d97a /activerecord/lib/active_record/associations/association_scope.rb
parent5c0e9333c0973123fb1ce2cde68a1c211d422f91 (diff)
downloadrails-3b87c38d029c1626161a3e7699d40da3e789d7cb.tar.gz
rails-3b87c38d029c1626161a3e7699d40da3e789d7cb.tar.bz2
rails-3b87c38d029c1626161a3e7699d40da3e789d7cb.zip
Fix belongs_to polymorphic with custom primary key on target.
Closes #3104.
Diffstat (limited to 'activerecord/lib/active_record/associations/association_scope.rb')
-rw-r--r--activerecord/lib/active_record/associations/association_scope.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/activerecord/lib/active_record/associations/association_scope.rb b/activerecord/lib/active_record/associations/association_scope.rb
index 9e6d9e73c5..a0efdbc2a4 100644
--- a/activerecord/lib/active_record/associations/association_scope.rb
+++ b/activerecord/lib/active_record/associations/association_scope.rb
@@ -68,7 +68,12 @@ module ActiveRecord
end
if reflection.source_macro == :belongs_to
- key = reflection.association_primary_key
+ if reflection.options[:polymorphic]
+ key = reflection.association_primary_key(klass)
+ else
+ key = reflection.association_primary_key
+ end
+
foreign_key = reflection.foreign_key
else
key = reflection.foreign_key