mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Don't call self.class unless necessary. Closes #3171.
This commit is contained in:
parent
4284e137ab
commit
adb8ac153f
2 changed files with 3 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue