method
preload_through_records
preload_through_records(records, reflection, through_association)
private
Hide source
# File activerecord/lib/active_record/association_preload.rb, line 243 def preload_through_records(records, reflection, through_association) through_reflection = reflections[through_association] through_primary_key = through_reflection.primary_key_name 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 through_records = [] records.each do |record| proxy = record.send(through_association) if proxy.respond_to?(:target) through_records << proxy.target proxy.reset else # this is a has_one :through reflection through_records << proxy if proxy end end through_records.flatten! else records.first.class.preload_associations(records, through_association) through_records = records.map {|record| record.send(through_association)}.flatten end through_records.compact! through_records end