Module: Miscellany::ArbitraryPrefetch::ActiveRecordPreloaderPatch
- Defined in:
- lib/miscellany/active_record/arbitrary_prefetch.rb
Instance Method Summary collapse
Instance Method Details
#grouped_records(association, records, polymorphic_parent) ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/miscellany/active_record/arbitrary_prefetch.rb', line 143 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 |