-
Type: New Feature
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: None
-
None
Add transaction method to Mongoid documents and document classes. This method accepts a block, and all operation inside the block are wrapped in a mongodb transaction.
Successful Transaction
Person.transaction do # ... end
will result in:
- Client associated with the Person class starts a new session (see more about used clients below).
- A transaction is started on the created session.
- All the server commands issued by the code inside the block are sent with the session option.
- When the block is completed, the transaction is committed.
Failed Transaction
Failed transaction means that the code inside the transaction block raises an exception.
Person.transaction do # ... raise SomeError # ... end
will result in:
- Client associated with the Person class starts a new session (see more about used clients below).
NOTE
Callbacks are not in the scope of this ticket.
- A transaction is started on the created session.
- All the server commands issued by the code inside the block before the exception are sent with the session option.
- When the exception is raised, the transaction is aborted.
- has to be done before
-
MONGOID-5531 Add after_commit and after_rollback callbacks
- Closed
- is cloned by
-
MONGOID-5534 Add transaction method to Mongoid module
- Closed