Method: NoSE::Plans::UpdatePlan#initialize

Defined in:
lib/nose/plans/update_planner.rb

#initialize(statement, index, trees, update_steps, cost_model) ⇒ UpdatePlan

Returns a new instance of UpdatePlan.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/nose/plans/update_planner.rb', line 29

def initialize(statement, index, trees, update_steps, cost_model)
  @statement = statement
  @index = index
  @trees = trees
  @query_plans = nil # these will be set later when we pick indexes
  update_steps.each { |step| step.calculate_cost cost_model }
  @update_steps = update_steps
  @cost_model = cost_model

  # Update with fields specified in the settings and conditions
  # (rewrite from foreign keys to IDs if needed)
  @update_fields = if statement.is_a?(Connection) ||
                      statement.is_a?(Delete)
                     []
                   else
                     statement.settings.map(&:field)
                   end
  @update_fields += statement.conditions.each_value.map(&:field)
  @update_fields.map! do |field|
    field.is_a?(Fields::ForeignKeyField) ? field.entity.id_field : field
  end
end