Class: OccamsRecord::EagerLoaders::PolymorphicBelongsTo
- Inherits:
-
Object
- Object
- OccamsRecord::EagerLoaders::PolymorphicBelongsTo
- Defined in:
- lib/occams-record/eager_loaders/polymorphic_belongs_to.rb
Overview
Eager loader for polymorphic belongs tos
Instance Attribute Summary collapse
-
#name ⇒ String
readonly
Association name.
Instance Method Summary collapse
-
#initialize(ref, scope = nil, use: nil, as: nil) { ... } ⇒ PolymorphicBelongsTo
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) { ... } ⇒ PolymorphicBelongsTo
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.
16 17 18 19 20 21 |
# File 'lib/occams-record/eager_loaders/polymorphic_belongs_to.rb', line 16 def initialize(ref, scope = nil, use: nil, as: nil, &eval_block) @ref, @scope, @use, @eval_block = ref, scope, use, eval_block @name = (as || ref.name).to_s @foreign_type = @ref.foreign_type.to_sym @foreign_key = @ref.foreign_key.to_sym end |
Instance Attribute Details
#name ⇒ String (readonly)
Returns association name.
6 7 8 |
# File 'lib/occams-record/eager_loaders/polymorphic_belongs_to.rb', line 6 def name @name end |
Instance Method Details
#run(rows, query_logger: nil) ⇒ Object
Run the query and merge the results into the given rows.
29 30 31 32 33 34 |
# File 'lib/occams-record/eager_loaders/polymorphic_belongs_to.rb', line 29 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 |