method
preload_through_records
v3.0.9 -
Show latest stable
- Class:
ActiveRecord::AssociationPreload::ClassMethods
preload_through_records(records, reflection, through_association)private
No documentation available.
# File activerecord/lib/active_record/association_preload.rb, line 267
def preload_through_records(records, reflection, through_association)
through_reflection = reflections[through_association]
through_primary_key = through_reflection.primary_key_name
through_records = []
if reflection.options[:source_type]
interface = reflection.source_reflection.options[:foreign_type]
preload_options = {:conditions => ["#{connection.quote_column_name interface} = ?", reflection.options[:source_type]]}
records.compact!
records.first.class.preload_associations(records, through_association, preload_options)
# Dont cache the association - we would only be caching a subset
records.each do |record|
proxy = record.send(through_association)
if proxy.respond_to?(:target)
through_records.concat Array.wrap(proxy.target)
proxy.reset
else # this is a has_one :through reflection
through_records << proxy if proxy
end
end
else
options = {}
options[:include] = reflection.options[:include] || reflection.options[:source] if reflection.options[:conditions] || reflection.options[:order]
options[:order] = reflection.options[:order]
options[:conditions] = reflection.options[:conditions]
records.first.class.preload_associations(records, through_association, options)
records.each do |record|
through_records.concat Array.wrap(record.send(through_association))
end
end
through_records
end