diff options
author | Jon Leighton <j@jonathanleighton.com> | 2011-09-26 15:41:31 +0100 |
---|---|---|
committer | Jon Leighton <j@jonathanleighton.com> | 2011-09-26 15:42:34 +0100 |
commit | 3b87c38d029c1626161a3e7699d40da3e789d7cb (patch) | |
tree | b056af6ff031bf5ee83e9d8a25307ae72668d97a /activerecord/lib/active_record/associations/association_scope.rb | |
parent | 5c0e9333c0973123fb1ce2cde68a1c211d422f91 (diff) | |
download | rails-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.rb | 7 |
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 |