Class: ROM::SQL::Commands::Update

Inherits:
Commands::Update
  • Object
show all
Includes:
ErrorWrapper, Transaction
Defined in:
lib/rom/sql/commands/update.rb

Instance Method Summary collapse

Methods included from ErrorWrapper

#call

Methods included from Transaction

#transaction

Instance Method Details

#change(original) ⇒ Object



30
31
32
# File 'lib/rom/sql/commands/update.rb', line 30

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

#execute(tuple) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rom/sql/commands/update.rb', line 17

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

  changed = diff(attributes.to_h)

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

#primary_keyObject



41
42
43
# File 'lib/rom/sql/commands/update.rb', line 41

def primary_key
  relation.primary_key
end

#update(tuple) ⇒ Object



34
35
36
37
38
39
# File 'lib/rom/sql/commands/update.rb', line 34

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