すべての変更をフラッシュせずに、単一のエンティティを Symfony に保存できますか? 例)
$em = $this->getDoctrine();
$entity1 = $em->find('\SomeEntity', 1);
$entity2 = $em->find('\SomeEntity', 2);
$entity1->setFoo(1);
$entity1->persist();
$entity2->setFoo(2);
$this->saveRightNow($entity2); // entity2 is written to the DB at this point
$em->flush(); // entity1 is written to the DB at this point
ソースコードを見ると、次を使用できるようDoctrine\ORM\UnitOfWork::commit
です:
function saveRightNow($entity) {
$em = $this->getDoctrine();
$uow = $em->getUnitOfWork();
$uow->commit($entity);
}
しかし、この方法の使用に関するドキュメントは見つかりませんでしcommit
た (内部関数としてマークされていなくても、使用に関するドキュメントはほとんどありません)。これは良い考えですか?それに危険はありますか?