Flowdock
method

preload_has_and_belongs_to_many_association

Importance_0
v2.1.0 - 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 94
      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 (?)"
        conditions << append_conditions(options, preload_options)

        associated_records = reflection.klass.find(:all, :conditions => [conditions, ids],
        :include => options[:include],
        :joins => "INNER JOIN #{connection.quote_table_name options[:join_table]} as 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 _parent_record_id",
        :order => options[:order])

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