Flowdock
method

preload_through_records

Importance_0
Ruby on Rails latest stable (v4.0.2) - 0 notes - Class: ActiveRecord::AssociationPreload::ClassMethods

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v3.0.9) is shown here.

preload_through_records(records, reflection, through_association) 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 267
      def preload_through_records(records, reflection, through_association)
        through_reflection = reflections[through_association]
        through_primary_key = through_reflection.primary_key_name

        through_records = []
        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
          records.each do |record|
            proxy = record.send(through_association)

            if proxy.respond_to?(:target)
              through_records.concat Array.wrap(proxy.target)
              proxy.reset
            else # this is a has_one :through reflection
              through_records << proxy if proxy
            end
          end
        else
          options = {}
          options[:include] = reflection.options[:include] || reflection.options[:source] if reflection.options[:conditions] || reflection.options[:order]
          options[:order] = reflection.options[:order]
          options[:conditions] = reflection.options[:conditions]
          records.first.class.preload_associations(records, through_association, options)

          records.each do |record|
            through_records.concat Array.wrap(record.send(through_association))
          end
        end
        through_records
      end
Register or log in to add new notes.