Permalink
Browse files

Don't call self.class unless necessary. Closes #3171.

  • Loading branch information...
1 parent 85f8458 commit 45c56bdd2da20149da851efbdb699574ba743e4e @jonleighton jonleighton committed Sep 29, 2011
Showing with 3 additions and 2 deletions.
  1. +2 −2 activerecord/lib/active_record/reflection.rb
  2. +1 −0 activerecord/test/cases/reflection_test.rb
@@ -224,8 +224,8 @@ def association_foreign_key
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
@@ -244,6 +244,7 @@ def test_association_primary_key
# 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

0 comments on commit 45c56bd

Please sign in to comment.