instance method
preload_has_many_association
Ruby on Rails 3.0.20
Since v2.2.3 Last seen in v3.0.20 PrivateSignature
preload_has_many_association(records, reflection, preload_options={})
No documentation comment.
Parameters
-
recordsreq -
reflectionreq -
preload_optionsopt = {}
Source
# File activerecord/lib/active_record/association_preload.rb, line 241
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
id_to_record_map, ids = construct_id_map(records, primary_key_name || reflection.options[:primary_key])
records.each {|record| record.send(reflection.name).loaded}
if options[:through]
through_records = preload_through_records(records, reflection, options[:through])
through_reflection = reflections[options[:through]]
unless through_records.empty?
source = reflection.source_reflection.name
through_records.first.class.preload_associations(through_records, source, options)
through_records.each do |through_record|
through_record_id = through_record[reflection.through_reflection_primary_key].to_s
add_preloaded_records_to_collection(id_to_record_map[through_record_id], reflection.name, through_record.send(source))
end
end
else
set_association_collection_records(id_to_record_map, reflection.name, find_associated_records(ids, reflection, preload_options),
reflection.primary_key_name)
end
end
Defined in activerecord/lib/active_record/association_preload.rb line 241
· View on GitHub
· Improve this page
· Find usages on GitHub