Skip to content
This repository has been archived by the owner on Apr 7, 2018. It is now read-only.

Commit

Permalink
#62 doctrine/phpcr-odm#582 - describing `Doctrine\ODM\PHPCR\DocumentM…
Browse files Browse the repository at this point in the history
…anager#transactional()` API
  • Loading branch information
Ocramius committed Dec 13, 2014
1 parent 72fa6d4 commit 25ce0ca
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions en/reference/transactions.rst
Expand Up @@ -4,3 +4,36 @@ Transactions
============

The ODM provides transaction support if the underlying persistence layer supports them.


transactional()
~~~~~~~~~~~~~~~

The ``Doctrine\ODM\PHPCR\DocumentManager#transactional()`` method provides support for, executing
functions in a transactional-safe manner if the underlying PHPCR transport supports it. Any PHP
``callable`` type is supported.

Example:

.. code-block:: php
<?php
use Doctrine\ODM\PHPCR\DocumentManager;
$documentManager = new DocumentManager($session);
$documentManager->transactional(function(DocumentManager $documentManager) {
$document = new Article('Cool story!');
$comment = $article->comment('Amazing indeed!');
$documentManager->persist($document);
$documentManager->persist($comment);
});
As you can see, there is also no need to call ``Doctrine\ODM\PHPCR\DocumentManager#flush()``,
since ``Doctrine\ODM\PHPCR\DocumentManager#transactional()`` will do it implicitly.

If an ``Exception`` is thrown during ``Doctrine\ODM\PHPCR\DocumentManager#transactional()``
execution, then the ``Doctrine\ODM\PHPCR\DocumentManager`` will be closed and the current transaction
rolled back.

0 comments on commit 25ce0ca

Please sign in to comment.