rom-rb / rom

Data mapping and persistence toolkit for Ruby
https://rom-rb.org
MIT License
2.08k stars 161 forks source link

Pass command options to changeset #596

Open qortex opened 4 years ago

qortex commented 4 years ago

We could provide command options while constructing a changeset object. For now, options are not passed down to the command being built inside the changeset.

Examples

When result is supposed to be :many instead of the default :one value for the command:

rel.changeset(:delete, command_options: { result: :many } )
# or directly
rel.changeset(:delete, result: :many )
# or
rel.changeset(:delete).with_command_options(result: :many)

Right now, it is not possible with the current changeset implementation (arguments are considered data, see this file) so we have to circumvent:

c = rel.changeset(:delete)
c.command_options[:result] = :many
c.commit
qortex commented 4 years ago

Note: Following a discussion on zulip with @solnic https://rom-rb.zulipchat.com/#narrow/stream/191800-general/topic/rom-sql/near/193048419