method
records_by_owner
rails latest stable - Class:
ActiveRecord::Associations::Preloader::ThroughAssociation
records_by_owner()public
No documentation available.
# File activerecord/lib/active_record/associations/preloader/through_association.rb, line 11
def records_by_owner
return @records_by_owner if defined?(@records_by_owner)
@records_by_owner = owners.each_with_object({}) do |owner, result|
if loaded?(owner)
result[owner] = target_for(owner)
next
end
through_records = through_records_by_owner[owner] || []
if owners.first.association(through_reflection.name).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