Flowdock
method

preload_has_and_belongs_to_many_association

Importance_0
v3.0.9 - Show latest stable - 0 notes - Class: ActiveRecord::AssociationPreload::ClassMethods
preload_has_and_belongs_to_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 188
      def preload_has_and_belongs_to_many_association(records, reflection, preload_options={})
        table_name = reflection.klass.quoted_table_name
        id_to_record_map, ids = construct_id_map(records)
        records.each {|record| record.send(reflection.name).loaded}
        options = reflection.options

        conditions = "t0.#{reflection.primary_key_name} #{in_or_equals_for_ids(ids)}"
        conditions << append_conditions(reflection, preload_options)

        associated_records_proxy = reflection.klass.unscoped.
            includes(options[:include]).
            joins("INNER JOIN #{connection.quote_table_name options[:join_table]} t0 ON #{reflection.klass.quoted_table_name}.#{reflection.klass.primary_key} = t0.#{reflection.association_foreign_key}").
            select("#{options[:select] || table_name+'.*'}, t0.#{reflection.primary_key_name} as the_parent_record_id").
            order(options[:order])

        all_associated_records = associated_records(ids) do |some_ids|
          associated_records_proxy.where([conditions, ids]).to_a
        end

        set_association_collection_records(id_to_record_map, reflection.name, all_associated_records, 'the_parent_record_id')
      end
Register or log in to add new notes.