220
221
222
223
224
225
226
227
228
229
230
231
|
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 220
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
|