In our applications, it is common to perform a number of database operations in one action. The question in every developer's mind is, what if something goes wrong? In that case, we are left in a state where some of the data has been updated while the rest has not. To circumvent this issue, we use database transactions to ensure that either we do a full update of all the related data, or rollback the changes if something goes wrong.
Phalcon offers the \Phalcon\Mvc\Model\Transaction\*
classes to allow for an easy and convenient way to perform transactional writes to our database. Imagine a business rule in our application, where a User
entity has at least one Address
entity. Also assume that our UI has relevant functionality to allow for input of many addresses per user. Once that payload is posted to our controller, we need to first save the user related data and then save any addresses that have been submitted, binding the User...