instance method preload_through_records

Ruby on Rails 2.3.18

Since v2.2.3 Last seen in v3.0.20 Private

Available in: v2.2.3 v2.3.18 v3.0.20

Signature

preload_through_records(records, reflection, through_association)

No documentation comment.

Parameters

records req
reflection req
through_association req
Source
# File activerecord/lib/active_record/association_preload.rb, line 260
      def preload_through_records(records, reflection, through_association)
        through_reflection = reflections[through_association]
        through_primary_key = through_reflection.primary_key_name

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

            if proxy.respond_to?(:target)
              through_records << proxy.target
              proxy.reset
            else # this is a has_one :through reflection
              through_records << proxy if proxy
            end
          end
          through_records.flatten!
        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)
          through_records = records.map {|record| record.send(through_association)}.flatten
        end
        through_records.compact!
        through_records
      end

Defined in activerecord/lib/active_record/association_preload.rb line 260 · View on GitHub · Improve this page · Find usages on GitHub

Defined in ActiveRecord::AssociationPreload::ClassMethods

Type at least 2 characters to search.

↑↓ navigate · open · esc close