aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/association_preload.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-09 18:37:01 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-11 13:45:08 -0800
commit681ab53ba15f9fc95c8a91e50bb0138aa66967b2 (patch)
tree0b819a5f2fe4e3e648876f134104d3c451adcb34 /activerecord/lib/active_record/association_preload.rb
parent42b2e4f85bef64b7aa1382e96c79db1d4f318a56 (diff)
downloadrails-681ab53ba15f9fc95c8a91e50bb0138aa66967b2.tar.gz
rails-681ab53ba15f9fc95c8a91e50bb0138aa66967b2.tar.bz2
rails-681ab53ba15f9fc95c8a91e50bb0138aa66967b2.zip
Get rid of set_association_target and association_loaded? as the parts of the code that need that can now just use association_proxy(:name).loaded?/target=
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r--activerecord/lib/active_record/association_preload.rb19
1 files changed, 13 insertions, 6 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index bb7ddfcae9..4c517e3339 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -133,7 +133,7 @@ module ActiveRecord
def add_preloaded_record_to_collection(parent_records, reflection_name, associated_record)
parent_records.each do |parent_record|
- parent_record.send("set_#{reflection_name}_target", associated_record)
+ parent_record.send(:association_proxy, reflection_name).target = associated_record
end
end
@@ -158,14 +158,17 @@ module ActiveRecord
seen_keys[seen_key] = true
mapped_records = id_to_record_map[seen_key]
mapped_records.each do |mapped_record|
- association_proxy = mapped_record.send("set_#{reflection_name}_target", associated_record)
+ association_proxy = mapped_record.send(:association_proxy, reflection_name)
+ association_proxy.target = associated_record
association_proxy.send(:set_inverse_instance, associated_record)
end
end
id_to_record_map.each do |id, records|
next if seen_keys.include?(id.to_s)
- records.each {|record| record.send("set_#{reflection_name}_target", nil) }
+ records.each do |record|
+ record.send(:association_proxy, reflection_name).target = nil
+ end
end
end
@@ -232,10 +235,14 @@ module ActiveRecord
end
def preload_has_one_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
+ return if records.first.send(:association_proxy, reflection.name).loaded?
id_to_record_map, ids = construct_id_map(records, reflection.options[:primary_key])
options = reflection.options
- records.each {|record| record.send("set_#{reflection.name}_target", nil)}
+
+ records.each do |record|
+ record.send(:association_proxy, reflection.name).target = nil
+ end
+
if options[:through]
through_records = preload_through_records(records, reflection, options[:through])
@@ -317,7 +324,7 @@ module ActiveRecord
end
def preload_belongs_to_association(records, reflection, preload_options={})
- return if records.first.send("loaded_#{reflection.name}?")
+ return if records.first.send(:association_proxy, reflection.name).loaded?
options = reflection.options
klasses_and_ids = {}