Module: ActiveRecordInheritPreloadAssocPrepend
- Defined in:
- lib/active_record_inherit_assoc.rb
Instance Method Summary collapse
- #associated_records_by_owner(*args) ⇒ Object
- #filter_associated_records_with_inherit!(owner, associated_records, inherit) ⇒ Object
Instance Method Details
#associated_records_by_owner(*args) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/active_record_inherit_assoc.rb', line 41 def associated_records_by_owner(*args) super.tap do |result| next unless inherit = reflection.[:inherit] result.each do |owner, associated_records| filter_associated_records_with_inherit!(owner, associated_records, inherit) end end end |
#filter_associated_records_with_inherit!(owner, associated_records, inherit) ⇒ Object
50 51 52 53 54 55 56 |
# File 'lib/active_record_inherit_assoc.rb', line 50 def filter_associated_records_with_inherit!(owner, associated_records, inherit) associated_records.select! do |record| Array(inherit).all? do |association| record.send(association) == owner.send(association) end end end |