Class: OccamsRecord::EagerLoaders::BelongsTo
- Defined in:
- lib/occams-record/eager_loaders/belongs_to.rb
Overview
Eager loader for belongs_to associations.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#merge!(assoc_rows, rows) ⇒ Object
Merge the association rows into the given rows.
-
#query(rows) { ... } ⇒ Object
Yield one or more ActiveRecord::Relation objects to a given block.
Methods inherited from Base
Constructor Details
This class inherits a constructor from OccamsRecord::EagerLoaders::Base
Instance Method Details
#merge!(assoc_rows, rows) ⇒ Object
Merge the association rows into the given rows.
22 23 24 25 |
# File 'lib/occams-record/eager_loaders/belongs_to.rb', line 22 def merge!(assoc_rows, rows) Merge.new(rows, name). single!(assoc_rows, @ref.foreign_key.to_s, @model.primary_key.to_s) end |
#query(rows) { ... } ⇒ Object
Yield one or more ActiveRecord::Relation objects to a given block.
11 12 13 14 |
# File 'lib/occams-record/eager_loaders/belongs_to.rb', line 11 def query(rows) ids = rows.map { |r| r.send @ref.foreign_key }.compact.uniq yield base_scope.where(@ref.active_record_primary_key => ids) end |