Class: ROM::SQL::Commands::Update
- Inherits:
-
Commands::Update
- Object
- Commands::Update
- ROM::SQL::Commands::Update
- Extended by:
- Deprecations
- Includes:
- 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
59 60 61 62 |
# File 'lib/rom/sql/commands/update.rb', line 59 def change(original) Deprecations.warn("#{self.class}#change is deprecated. Use repositories with changesets instead") self.class.build(relation, .merge(original: original.to_h)) end |
#execute(tuple) ⇒ Array<Hash>, Hash
Updates existing tuple in a relation
33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rom/sql/commands/update.rb', line 33 def execute(tuple) attributes = input[tuple] validator.call(attributes) changed = diff(attributes.to_h) if changed.size > 0 update(changed) else EMPTY_ARRAY end end |