method

preload_has_many_association

Importance_0
v2.1.0 - Show latest stable - 0 notes - Class: ActiveRecord::AssociationPreload::ClassMethods
preload_has_many_association(records, reflection, preload_options={}) private

No documentation

This method has no description. You can help the Ruby on Rails community by adding new notes.

Hide source
# File activerecord/lib/active_record/association_preload.rb, line 135
      def preload_has_many_association(records, reflection, preload_options={})
        id_to_record_map, ids = construct_id_map(records)
        records.each {|record| record.send(reflection.name).loaded}
        options = reflection.options

        if options[:through]
          through_records = preload_through_records(records, reflection, options[:through])
          through_reflection = reflections[options[:through]]
          through_primary_key = through_reflection.primary_key_name
          unless through_records.empty?
            source = reflection.source_reflection.name
            #add conditions from reflection!
            through_records.first.class.preload_associations(through_records, source, reflection.options)
            through_records.each do |through_record|
              add_preloaded_records_to_collection(id_to_record_map[through_record[through_primary_key].to_s],
                                                 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
Register or log in to add new notes.