Flowdock
method

records_by_owner

Importance_0
v6.0.0 - Show latest stable - 0 notes - Class: ThroughAssociation
records_by_owner() public

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/associations/preloader/through_association.rb, line 18
        def records_by_owner
          return @records_by_owner if defined?(@records_by_owner)
          source_records_by_owner = source_preloaders.map(&:records_by_owner).reduce(:merge)
          through_records_by_owner = through_preloaders.map(&:records_by_owner).reduce(:merge)

          @records_by_owner = owners.each_with_object({}) do |owner, result|
            through_records = through_records_by_owner[owner] || []

            if @already_loaded
              if source_type = reflection.options[:source_type]
                through_records = through_records.select do |record|
                  record[reflection.foreign_type] == source_type
                end
              end
            end

            records = through_records.flat_map do |record|
              source_records_by_owner[record]
            end

            records.compact!
            records.sort_by! { |rhs| preload_index[rhs] } if scope.order_values.any?
            records.uniq! if scope.distinct_value
            result[owner] = records
          end
        end
Register or log in to add new notes.