ste
ste

Reputation: 1529

Doctrine, how to handle multiple flush()

In my Symfony 2 application I have the following scenario, in this order:

  1. in my controller I do some edit on a managed entity (i.e. retrived from db or persisted to the entity manager)
  2. if something happen, in my controller (or in a external service got from the container) I do some other edit in other entities, or i instanciate some new entities. I want to flush these operations (only these described at point 2) immediatly
  3. if something else happen, I want to edit some other entities and I want to flush changes made in (1) and in (3). Otherwise, i don't want to flush changes made in (1) and in (3)

Is there a way to do this in Doctrine, e.g. managing multiple unit of work at the same time or something similar? Otherwise I was looking at this http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/dql-doctrine-query-language.html#update-queries, i.e. single queries for each update made in point (2) and this http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/query-builder.html#sql-query-builder for insertions made in point (2) but I was wondering if there is a better approach.

Upvotes: 0

Views: 2842

Answers (2)

Vladislav
Vladislav

Reputation: 357

You can split your "system" entities and "program" entities and use 2 connections. Have a look here

Upvotes: 1

Mikhail Prosalov
Mikhail Prosalov

Reputation: 4345

You can detach entities that you don't want to be flushed and call $em->flush();

$em->detach($entity);

Upvotes: 1

Related Questions