aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-09-29 17:59:40 +0100
committerJon Leighton <j@jonathanleighton.com>2011-09-29 18:00:30 +0100
commitadb8ac153f8e9e497eaecf62165c0bd53c18149a (patch)
tree6dc889f21b62a83f55653a7acc9fe84205850cc3 /activerecord
parent4284e137ab876927b15d593358a157fe077ec238 (diff)
downloadrails-adb8ac153f8e9e497eaecf62165c0bd53c18149a.tar.gz
rails-adb8ac153f8e9e497eaecf62165c0bd53c18149a.tar.bz2
rails-adb8ac153f8e9e497eaecf62165c0bd53c18149a.zip
Don't call self.class unless necessary. Closes #3171.
Diffstat (limited to 'activerecord')
-rw-r--r--activerecord/lib/active_record/reflection.rb4
-rw-r--r--activerecord/test/cases/reflection_test.rb1
2 files changed, 3 insertions, 2 deletions
diff --git a/activerecord/lib/active_record/reflection.rb b/activerecord/lib/active_record/reflection.rb
index 1929a808ed..120ff0cac6 100644
--- a/activerecord/lib/active_record/reflection.rb
+++ b/activerecord/lib/active_record/reflection.rb
@@ -212,8 +212,8 @@ module ActiveRecord
end
# klass option is necessary to support loading polymorphic associations
- def association_primary_key(klass = self.klass)
- options[:primary_key] || klass.primary_key
+ def association_primary_key(klass = nil)
+ options[:primary_key] || (klass || self.klass).primary_key
end
def active_record_primary_key
diff --git a/activerecord/test/cases/reflection_test.rb b/activerecord/test/cases/reflection_test.rb
index 0a48f418b1..ca9d88fbd5 100644
--- a/activerecord/test/cases/reflection_test.rb
+++ b/activerecord/test/cases/reflection_test.rb
@@ -244,6 +244,7 @@ class ReflectionTest < ActiveRecord::TestCase
# Normal association
assert_equal "id", Author.reflect_on_association(:posts).association_primary_key.to_s
assert_equal "name", Author.reflect_on_association(:essay).association_primary_key.to_s
+ assert_equal "name", Essay.reflect_on_association(:writer).association_primary_key.to_s
# Through association (uses the :primary_key option from the source reflection)
assert_equal "nick", Author.reflect_on_association(:subscribers).association_primary_key.to_s