Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 874 Bytes

transactions.md

File metadata and controls

25 lines (19 loc) · 874 Bytes

Cycle ORM - Transactions

To persist entity changes, your application services and controllers will require Cycle\ORM\TransactionInterface.

Default Configuration

By default, the framework will automatically create a transaction on-demand from the container. Considering that transactions always clean after the run operation, you can request it as a constructor parameter.

use Cycle\ORM;

class MyService
{
    private $tr;
    
    public function __construct(ORM\TransactionInterface $tr)
    {
        $this->tr = $tr;
    }
}

Make sure that persist/delete and run methods are always called within one method scope while using service-specific transactions.

Testing

You can always test the service by mocking TransactionInterface, consider binding mocked transaction object to your application instance to see what is being persisted.