aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/associations/preloader
diff options
context:
space:
mode:
authorRyuta Kamizono <kamipo@gmail.com>2017-09-18 11:42:29 +0900
committerRyuta Kamizono <kamipo@gmail.com>2017-09-18 11:42:29 +0900
commita1aa86b99e298c4a2b7a2e5da7a1bb9d8ba65a3b (patch)
treecfcb6c55e67aad9b48f0a2780bdf979ccadeef20 /activerecord/lib/active_record/associations/preloader
parent9b1115ea34e44fe772272ec58ccba7a9cbc0955a (diff)
downloadrails-a1aa86b99e298c4a2b7a2e5da7a1bb9d8ba65a3b.tar.gz
rails-a1aa86b99e298c4a2b7a2e5da7a1bb9d8ba65a3b.tar.bz2
rails-a1aa86b99e298c4a2b7a2e5da7a1bb9d8ba65a3b.zip
The name of the key on the owner is abstracted as `reflection.join_foreign_key`
Diffstat (limited to 'activerecord/lib/active_record/associations/preloader')
-rw-r--r--activerecord/lib/active_record/associations/preloader/association.rb10
-rw-r--r--activerecord/lib/active_record/associations/preloader/belongs_to.rb4
-rw-r--r--activerecord/lib/active_record/associations/preloader/has_many.rb4
-rw-r--r--activerecord/lib/active_record/associations/preloader/has_one.rb4
4 files changed, 5 insertions, 17 deletions
diff --git a/activerecord/lib/active_record/associations/preloader/association.rb b/activerecord/lib/active_record/associations/preloader/association.rb
index 323f25e37e..1e2d6c4f1e 100644
--- a/activerecord/lib/active_record/associations/preloader/association.rb
+++ b/activerecord/lib/active_record/associations/preloader/association.rb
@@ -27,16 +27,16 @@ module ActiveRecord
raise NotImplementedError
end
- # The name of the key on the model which declares the association
- def owner_key_name
- raise NotImplementedError
- end
-
private
def options
reflection.options
end
+ # The name of the key on the model which declares the association
+ def owner_key_name
+ reflection.join_foreign_key
+ end
+
def associated_records_by_owner(preloader)
records = load_records do |record|
owner = owners_by_key[convert_key(record[association_key_name])]
diff --git a/activerecord/lib/active_record/associations/preloader/belongs_to.rb b/activerecord/lib/active_record/associations/preloader/belongs_to.rb
index ae9695f26a..62df4f5530 100644
--- a/activerecord/lib/active_record/associations/preloader/belongs_to.rb
+++ b/activerecord/lib/active_record/associations/preloader/belongs_to.rb
@@ -7,10 +7,6 @@ module ActiveRecord
def association_key_name
options[:primary_key] || klass && klass.primary_key
end
-
- def owner_key_name
- reflection.foreign_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 29a1ce099d..9ff0aa24ab 100644
--- a/activerecord/lib/active_record/associations/preloader/has_many.rb
+++ b/activerecord/lib/active_record/associations/preloader/has_many.rb
@@ -7,10 +7,6 @@ module ActiveRecord
def association_key_name
reflection.foreign_key
end
-
- def owner_key_name
- reflection.active_record_primary_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 d87abf630f..e58fa351b0 100644
--- a/activerecord/lib/active_record/associations/preloader/has_one.rb
+++ b/activerecord/lib/active_record/associations/preloader/has_one.rb
@@ -7,10 +7,6 @@ module ActiveRecord
def association_key_name
reflection.foreign_key
end
-
- def owner_key_name
- reflection.active_record_primary_key
- end
end
end
end