I'm trying to refactor my code in my controller.
For now, i have all treatments in this controller and i finish with a flush()
in an action.
So, in an action, i can have many persist()
and just one flush()
at the end.
I'm working now to clean my controller, and create functions in all my repository to reduce the code.
But now i have a problem, if, before, for an action i was 10 persist()
and 1 flush()
, now i have 10 flush()
(one for each repository-function).
I think it is not a good solution to increase the number of flush()
like that, right ?
I have find something and i want to now, if with this code, there is always 10 flush()
each time ? Or just one when commit()
?
$em->getConnection()->beginTransaction(); // suspend auto-commit
try {
//... do some work
$user = new User;
$user->setName('George');
$em->persist($user);
$em->flush();
$em->getConnection()->commit();
} catch (Exception $e) {
$em->getConnection()->rollback();
$em->close();
throw $e;
}