Module: LunaPark::Extensions::Repositories::Postgres::Update
- Defined in:
- lib/luna_park/extensions/repositories/postgres/update.rb
Instance Method Summary collapse
-
#save(input, **scope_opts) ⇒ Object
rubocop:disable Metrics/AbcSize.
Instance Method Details
#save(input, **scope_opts) ⇒ Object
rubocop:disable Metrics/AbcSize
8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/luna_park/extensions/repositories/postgres/update.rb', line 8 def save(input, **scope_opts) # rubocop:disable Metrics/AbcSize entity = wrap(input) entity.updated_at = Time.now if entity.respond_to?(:updated_at) row = to_row(entity) new_row = scoped(**scope_opts).where(primary_key => row[primary_key]).returning.update(row).first found! new_row, not_found_by: { primary_key => row[primary_key] } new_attrs = from_row(new_row) entity.set_attributes(new_attrs) entity end |