diff options
author | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-18 12:14:20 +0900 |
---|---|---|
committer | Ryuta Kamizono <kamipo@gmail.com> | 2017-09-18 12:14:20 +0900 |
commit | dae16f8cd5908a0accfaf280d89b47b757c4bf2d (patch) | |
tree | 33c6e6a54d7b0a5660155fe8064eb6b73bc9cb6d /activerecord/lib/active_record/associations/preloader | |
parent | a1aa86b99e298c4a2b7a2e5da7a1bb9d8ba65a3b (diff) | |
download | rails-dae16f8cd5908a0accfaf280d89b47b757c4bf2d.tar.gz rails-dae16f8cd5908a0accfaf280d89b47b757c4bf2d.tar.bz2 rails-dae16f8cd5908a0accfaf280d89b47b757c4bf2d.zip |
The name of the key on the associated record is abstracted as `reflection.join_primary_key`
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader')
4 files changed, 5 insertions, 14 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb index 1e2d6c4f1e..8101c5604b 100644 --- a/activerecord/lib/active_record/associations/preloader/association.rb +++ b/activerecord/lib/active_record/associations/preloader/association.rb @@ -22,16 +22,16 @@ module ActiveRecord end end - # The name of the key on the associated records - def association_key_name - raise NotImplementedError - end - private def options reflection.options end + # The name of the key on the associated records + def association_key_name + reflection.join_primary_key(klass) + end + # The name of the key on the model which declares the association def owner_key_name reflection.join_foreign_key diff --git a/activerecord/lib/active_record/associations/preloader/belongs_to.rb b/activerecord/lib/active_record/associations/preloader/belongs_to.rb index 62df4f5530..a8e3340b23 100644 --- a/activerecord/lib/active_record/associations/preloader/belongs_to.rb +++ b/activerecord/lib/active_record/associations/preloader/belongs_to.rb @@ -4,9 +4,6 @@ module ActiveRecord module Associations class Preloader class BelongsTo < SingularAssociation #:nodoc: - def association_key_name - options[:primary_key] || klass && klass.primary_key - end end end end diff --git a/activerecord/lib/active_record/associations/preloader/has_many.rb b/activerecord/lib/active_record/associations/preloader/has_many.rb index 9ff0aa24ab..72f55bc43f 100644 --- a/activerecord/lib/active_record/associations/preloader/has_many.rb +++ b/activerecord/lib/active_record/associations/preloader/has_many.rb @@ -4,9 +4,6 @@ module ActiveRecord module Associations class Preloader class HasMany < CollectionAssociation #:nodoc: - def association_key_name - reflection.foreign_key - end end end end diff --git a/activerecord/lib/active_record/associations/preloader/has_one.rb b/activerecord/lib/active_record/associations/preloader/has_one.rb index e58fa351b0..e339b65fb5 100644 --- a/activerecord/lib/active_record/associations/preloader/has_one.rb +++ b/activerecord/lib/active_record/associations/preloader/has_one.rb @@ -4,9 +4,6 @@ module ActiveRecord module Associations class Preloader class HasOne < SingularAssociation #:nodoc: - def association_key_name - reflection.foreign_key - end end end end |