Class: ROM::FMP::Commands::Update

Inherits:
Commands::Update
  • Object
show all
Defined in:
lib/rom/fmp/commands/update.rb

Instance Method Summary collapse

Instance Method Details

#change(original) ⇒ Object



27
28
29
# File 'lib/rom/fmp/commands/update.rb', line 27

def change(original)
  self.class.new(relation, options.merge(original: original))
end

#execute(tuple) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/rom/fmp/commands/update.rb', line 14

def execute(tuple)
  attributes = input[tuple]
  validator.call(attributes)

  changed = diff(attributes.to_h)

  if changed.any?
    update(changed)
  else
    []
  end
end

#primary_keyObject



38
39
40
# File 'lib/rom/fmp/commands/update.rb', line 38

def primary_key
  relation.primary_key
end

#update(tuple) ⇒ Object



31
32
33
34
35
36
# File 'lib/rom/fmp/commands/update.rb', line 31

def update(tuple)
  pks = relation.map { |t| t[primary_key] }
  dataset = relation.dataset
  dataset.update(tuple)
  dataset.unfiltered.where(primary_key => pks).to_a
end