Module: Miscellany::ArbitraryPrefetch::ActiveRecordPatches::Associations::PreloaderPatch
- Defined in:
- lib/miscellany/active_record/arbitrary_prefetch.rb
Instance Method Summary collapse
Instance Method Details
#grouped_records(association, records, polymorphic_parent) ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 |
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 236 def grouped_records(association, records, polymorphic_parent) h = {} 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 |