Skip to content

Commit

Permalink
[skip ci] add transactions in doc
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Sep 24, 2020
1 parent 03ff5f0 commit 11e662d
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions docs/model/dao.rst
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,52 @@ Deletions example
The `DAO::flush()` method can be called if insertions, updates or deletions are pending.

Transactions
============
Explicit transactions
---------------------
All DAO operations can be inserted into a transaction, so that a series of changes can be atomized:

.. code-block:: php
try{
DAO::beginTransaction();
$orga=new Organization();
$orga->setName('Foo');
DAO::save($orga);
$user=new User();
$user->setFirstname('DOE');
$user->setOrganization($orga);
DAO::save($user);
DAO::commit();
}catch (\Exception $e){
DAO::rollBack();
}
In case of multiple databases defined in the configuration, transaction-related methods can take the database offset defined in parameter.

.. code-block:: php
DAO::beginTransaction('db-messagerie');
//some DAO operations on messagerie models
DAO::commit('db-messagerie');
Implicit transactions
---------------------

Some DAO methods implicitly use transactions to group together insert, update or delete operations.

.. code-block:: php
$users=DAO::getAll(User::class);
foreach ($users as $user){
$user->setSuspended(true);
DAO::toUpdate($user);
}
DAO::updateGroups();//Perform updates in a transaction
SDAO class
==========
The **SDAO** class accelerates CRUD operations for the business classes without relationships.
Expand Down

0 comments on commit 11e662d

Please sign in to comment.