When dealing with transactionless operations (MongoDB, ElasticSearch, etc.) it is not possible to redefine the transaction, yet it would make sense to have a rollback method that would yield the model that was created or updated (ie the return of the create/update method.
Based on that, it would become possible to either destroy or just rollback the changes manually (ActiveModel has a nice previous_changes builtin method)
class FooResource
def create(attributes)
Foo.create(attributes)
end
def rollback(resource:, method:)
if method == :create
resource.destroy
else
resource.update_attributes(resource.previous_changes)
end
end
The idea being that the rollback method would be fired automatically if there is for example a failure while persisting the related resources / sideposting
When dealing with transactionless operations (MongoDB, ElasticSearch, etc.) it is not possible to redefine the
transaction, yet it would make sense to have arollbackmethod that would yield the model that was created or updated (ie the return of thecreate/updatemethod.Based on that, it would become possible to either
destroyor just rollback the changes manually (ActiveModel has a niceprevious_changesbuiltin method)The idea being that the rollback method would be fired automatically if there is for example a failure while persisting the related resources / sideposting