aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/association_preload.rb
diff options
context:
space:
mode:
authorWill Bryant <will.bryant@gmail.com>2008-09-27 15:28:21 +1200
committerMichael Koziarski <michael@koziarski.com>2008-10-10 16:58:39 +0200
commit4c05055487e149bfa4152c1b42f3519671ca22ac (patch)
treee48d836fa25a2c06544b792f4d72c0f7051be9ee /activerecord/lib/active_record/association_preload.rb
parent28393e6e9c9368036e65e77175ea4f65a862259c (diff)
downloadrails-4c05055487e149bfa4152c1b42f3519671ca22ac.tar.gz
rails-4c05055487e149bfa4152c1b42f3519671ca22ac.tar.bz2
rails-4c05055487e149bfa4152c1b42f3519671ca22ac.zip
explicitly including child associations that are also included in the parent association definition should not result in double records in the collection/double loads (#1110)
Signed-off-by: Michael Koziarski <michael@koziarski.com> [#1110 state:committed]
Diffstat (limited to 'activerecord/lib/active_record/association_preload.rb')
-rw-r--r--activerecord/lib/active_record/association_preload.rb3
1 files changed, 3 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/association_preload.rb b/activerecord/lib/active_record/association_preload.rb
index 99e3973830..6e194ab9b4 100644
--- a/activerecord/lib/active_record/association_preload.rb
+++ b/activerecord/lib/active_record/association_preload.rb
@@ -193,6 +193,7 @@ module ActiveRecord
end
def preload_has_one_association(records, reflection, preload_options={})
+ return if records.first.send("loaded_#{reflection.name}?")
id_to_record_map, ids = construct_id_map(records)
options = reflection.options
records.each {|record| record.send("set_#{reflection.name}_target", nil)}
@@ -214,6 +215,7 @@ module ActiveRecord
end
def preload_has_many_association(records, reflection, preload_options={})
+ return if records.first.send(reflection.name).loaded?
options = reflection.options
primary_key_name = reflection.through_reflection_primary_key_name
@@ -271,6 +273,7 @@ module ActiveRecord
end
def preload_belongs_to_association(records, reflection, preload_options={})
+ return if records.first.send("loaded_#{reflection.name}?")
options = reflection.options
primary_key_name = reflection.primary_key_name