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
169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 169 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 |