153
154
155
156
157
158
159
160
161
162
163
164
|
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 153
def grouped_records
h = {}
polymorphic_parent = !root? && parent.polymorphic?
source_records.each do |record|
next unless record
reflection = record.class._reflect_on_association(association)
reflection ||= record.association(association)&.reflection rescue nil
next if polymorphic_parent && !reflection || !record.association(association).klass
(h[reflection] ||= []) << record
end
h
end
|