Class: ROM::SQL::Commands::Update
- Inherits:
-
Commands::Update
- Object
- Commands::Update
- ROM::SQL::Commands::Update
- Includes:
- Deprecations, ErrorWrapper, Transaction
- Defined in:
- lib/rom/sql/commands/update.rb
Overview
Update command
Instance Method Summary collapse
-
#change(original) ⇒ Command::Update
Update existing tuple only when it changed.
-
#execute(tuple) ⇒ Array<Hash>, Hash
Updates existing tuple in a relation.
Methods included from ErrorWrapper
Methods included from Transaction
Instance Method Details
#change(original) ⇒ Command::Update
Update existing tuple only when it changed
57 58 59 |
# File 'lib/rom/sql/commands/update.rb', line 57 def change(original) self.class.build(relation, .merge(original: original.to_h)) end |
#execute(tuple) ⇒ Array<Hash>, Hash
Updates existing tuple in a relation
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rom/sql/commands/update.rb', line 31 def execute(tuple) attributes = input[tuple] validator.call(attributes) changed = diff(attributes.to_h) if changed.any? update(changed) else [] end end |