propel には findOneOrCreate()があります
例。
$bookTag = BookTagQuery::create()
->filterByBook($book)
->findOneOrCreate();
ドクトリンでは、コントローラーのどこでもそのようなことができます。
...................
$filename='something';
$document_exists = $em->getRepository('DemoBundle:Document')
->findOneBy(array('filename' => $filename));
if (null === $document_exists) {
$document = new Document();
$document->setFilename($filename);
$em->persist($document);
$em->flush();
}
Doctrineでこれを達成する別の方法はありますか?
エンティティ リポジトリ内でエンティティ マネージャを呼び出しても問題ありませんか? 助言がありますか?