-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TransactionWrite update() with a block #846
base: master
Are you sure you want to change the base?
Conversation
…te operations on fields
def update(model, &block) | ||
action = Dynamoid::TransactionWrite::Update.new(model, raise_error: false, &block) | ||
register_action action | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This new transactional method #update
behaves a bit differently than the non-transactional one. Non-transactional updates a model and its fields with new values. It's easy enough because UpdateItem
may be configured to return all attributes of an updated item. TransactWriteItems
doesn't support this AFAIK. And manually implement logic of remove
/add
operations to update attributes in memory also doesn't appeal to me. So accepting a model as a parameter seems incorrect to me.
Instead I would propose to accept a primary key as a parameter. There is no such non-transactional method but I will add it later to complement existing #update
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct. Because of that should we just change update_fields to optionally allow a block or do you think adding an entirely new method to TransactionWrite would be better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer adding new method update
in the TransactionWrite
module (like it was already done here).
I overlooked that semantic of existing .update
method is find && update_attributes
. And indeed .update_fields
looks very close to the #update
method.
So go ahead with adding a block parameter to the existing transactional method .update_fields
.
else | ||
remove(field_or_values) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to have a separate class to collect user actions (I mean to set/add/delete), similar to ItemUpdater
(https://github.com/Dynamoid/dynamoid/blob/master/lib/dynamoid/adapter_plugin/aws_sdk_v3/item_updater.rb)
@@ -1106,6 +1106,7 @@ model | |||
* `#destroy`/`#destroy!` - remove an model | |||
* `#upsert` - add a new model or update an existing one, no callbacks | |||
* `#update_fields` - update a model without its instantiation | |||
* `#update` - update a model using a block that supports set, add, and delete operations on fields |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* `#update` - update a model using a block that supports set, add, and delete operations on fields | |
* `#update` - update a model using a block that supports set, add, remove, and delete operations on fields |
WIP