Class: DeepPreloader::WorklistContext

Inherits:
Struct
  • Object
show all
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

Instance Method Summary collapse

Instance Attribute Details

#child_constraintsObject

Returns the value of attribute child_constraints

Returns:

  • (Object)

    the current value of child_constraints



187
188
189
# File 'lib/deep_preloader.rb', line 187

def child_constraints
  @child_constraints
end

#child_key_columnObject

Returns the value of attribute child_key_column

Returns:

  • (Object)

    the current value of child_key_column



187
188
189
# File 'lib/deep_preloader.rb', line 187

def child_key_column
  @child_key_column
end

#child_typeObject

Returns the value of attribute child_type

Returns:

  • (Object)

    the current value of 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