Flowdock
method

preload_has_and_belongs_to_many_association

Importance_0
v2.3.2 - 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 177
      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 = reflection.klass.with_exclusive_scope do
          reflection.klass.find(:all, :conditions => [conditions, ids],
            :include => 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])
        end
        set_association_collection_records(id_to_record_map, reflection.name, associated_records, 'the_parent_record_id')
      end
Register or log in to add new notes.