2. - Transactions are protective blocks
- Makes sense if some operations are interdependent.
- Transactions enforce the integrity of the database
- Guard the data against program errors or database break-downs
Introduction
3. - Basically you should use transaction blocks whenever you have a number
of statements that must be executed together or not at all.
- The classic example is a transfer between two accounts where you can
only have a deposit if the withdrawal succeeded and vice versa
Use Cases
4. - save and destroy are automatically wrapped in a transaction
Alternative way
5. - Exceptions thrown within a transaction block will be propagated (after
triggering the ROLLBACK)
- ActiveRecord::Rollback exception, triggers a ROLLBACK when raised
- not be re-raised by the transaction block.
Transaction Rollback Triggers
6. - There are two types of callbacks associated with committing and rolling
back transactions:
- after_commit
- after_rollback
Callbacks