High
Database
Use transactions for multi-step operations
Official
Rule Description
Wrap multi-step database operations in transactions:
- Ensures all-or-nothing execution
- Prevents partial updates on failure
- Maintains data consistency
```ruby
ActiveRecord::Base.transaction do
order.update!(status: 'paid')
Payment.create!(order: order, amount: order.total)
InventoryService.decrement(order.items)
end
# If any step fails, all changes are rolled back
```
Included in Rulesets
Add This Rule
Sign in to add this rule to your workspace
Sign in with GitHubDetails
- Severity
- High
- Category
- Database
- Used in
- 6 rulesets