私の質問はDoctrineの多対多関係とonFlushイベントに言及されています
著者エンティティ: http://pastebin.com/GBCaSA4Z 書籍エンティティ: http://pastebin.com/Xb2SEiaQ
私はこのコードを実行します:
$book = new \App\CoreBundle\Entity\Books();
$book->setTtile('book title: '.uniqid());
$book->setIsbn('book isbn: '.uniqid());
$author = new \App\CoreBundle\Entity\Authors();
$author->setName('author title: '.uniqid());
$author->addBook($book);
$entityManager->persist($author);
$entityManager->flush();
このようにして、すべてOKです。Doctrine は 3 つのクエリを生成します: create author、create book、および author_books でのリンクの作成です。
しかし、Doctrine onFlushイベントですべてのエンティティをデタッチしてシリアライズし、NoSQL データベースに保存する必要があります。そして、他のスクリプトはこれらすべてのエンティティのシリアル化を解除し、データベースに保存します。このようにして、Doctrine は create book と create author の 2 つの SQL クエリのみを生成します。テーブルをリンクするためのSQLクエリもdoctrineで生成するにはどうすればよいですか?
エンティティをシリアル化解除するスクリプトの一部:
foreach ($serializedEntities as $serializedEntity)
{
$detachedEtity = unserialize($serializedEntity);
$entity = $entityManager->merge($detachedEtity);
//$entityManager->persist($entity)
}
$entityManager->flush();
更新:そして、私は常に次のようなエラーが発生します:
Notice: Undefined index: 000000002289c17b000000003937ebb0 in /app/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2776