Skip to content
Vladislav Trotsenko edited this page Sep 29, 2019 · 1 revision

Synopsis

Provides to assign model into context. Supports assign by relation chain, relation find_by.

Examples of usage

Find relation mode

class SomeOperation < ApplicationOperation
  step ->(ctx, **) { ctx[:some_model] = SomeModel.create }
  step Macro::Model(
    entity: :some_model, connections: %i[sub_object items], find_by_key: :id, params_key: :value
  ) # ctx[:model] = ctx[:some_model].sub_object.items.find_by(id: :value)
end

Assign by relation chain mode

class SomeOperation < ApplicationOperation
  step ->(ctx, **) { ctx[:some_model] = SomeModel.create }
  step Macro::Model(
    entity: :some_model, connections: %i[sub_object items], assign: true
  ) # ctx[:model] = ctx[:some_model].sub_object.items
end
Clone this wiki locally