Class: OccamsRecord::EagerLoaders::Base
- Inherits:
-
Object
- Object
- OccamsRecord::EagerLoaders::Base
- Defined in:
- lib/occams-record/eager_loaders/base.rb
Overview
Base class for eagoer loading an association.
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Association name.
Instance Method Summary collapse
-
#initialize(ref, scope = nil, use: nil, as: nil) { ... } ⇒ Base
constructor
ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you’ve defined on the model.
-
#run(rows, query_logger: nil) ⇒ Object
Run the query and merge the results into the given rows.
Constructor Details
#initialize(ref, scope = nil, use: nil, as: nil) { ... } ⇒ Base
ActiveRecord::Relation on which you may call all the normal query hethods (select, where, etc) as well as any scopes you’ve defined on the model.
18 19 20 21 22 |
# File 'lib/occams-record/eager_loaders/base.rb', line 18 def initialize(ref, scope = nil, use: nil, as: nil, &eval_block) @ref, @scope, @use, @as, @eval_block = ref, scope, use, as, eval_block @model = ref.klass @name = (as || ref.name).to_s end |
Instance Attribute Details
#name ⇒ String (readonly)
8 9 10 |
# File 'lib/occams-record/eager_loaders/base.rb', line 8 def name @name end |
Instance Method Details
#run(rows, query_logger: nil) ⇒ Object
Run the query and merge the results into the given rows.
30 31 32 33 34 35 |
# File 'lib/occams-record/eager_loaders/base.rb', line 30 def run(rows, query_logger: nil) query(rows) { |scope| assoc_rows = Query.new(scope, use: @use, query_logger: query_logger, &@eval_block).run merge! assoc_rows, rows } end |