Class: DeepPreloader::WorklistContext
- Inherits:
-
Struct
- Object
- Struct
- DeepPreloader::WorklistContext
- Defined in:
- lib/deep_preloader.rb
Overview
entries need to be grouped by: child_type - look up in same table child_key - compare the same keys child_search_constraints - where constraints on child lookup such as polymorphic type or association scope.
Instance Attribute Summary collapse
-
#child_constraints ⇒ Object
Returns the value of attribute child_constraints.
-
#child_key_column ⇒ Object
Returns the value of attribute child_key_column.
-
#child_type ⇒ Object
Returns the value of attribute child_type.
Instance Method Summary collapse
Instance Attribute Details
#child_constraints ⇒ Object
Returns the value of attribute child_constraints
187 188 189 |
# File 'lib/deep_preloader.rb', line 187 def child_constraints @child_constraints end |
#child_key_column ⇒ Object
Returns the value of attribute child_key_column
187 188 189 |
# File 'lib/deep_preloader.rb', line 187 def child_key_column @child_key_column end |
#child_type ⇒ Object
Returns the value of attribute child_type
187 188 189 |
# File 'lib/deep_preloader.rb', line 187 def child_type @child_type end |
Instance Method Details
#load_children(keys, lock: nil) ⇒ Object
188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/deep_preloader.rb', line 188 def load_children(keys, lock: nil) scope = child_constraints.inject(child_type.unscoped) do |sc, (col, val)| sc.where(col => val) end if lock scope = scope.order(:id).lock(lock) end scope.where(child_key_column => keys).group_by { |c| c.read_attribute(child_key_column) } end |