Doctrine Many-to-many Relations And Onflush Event
Little example about Books and Authors: DB structure: Entities (they were generated form database using symfony2 console commands): Author: /** * Author * * @ORM\Table(name
Solution 1:
You need to ensure that both Book:authors and Author:books have the proper values before persisting.
Specifically:
classAuthors{
publicfunctionaddBook($book)
{
$this->books[] = $book;
$book->addAuthor($this);
}
Do the same on the Book entity.
BTW, change Books and Authors to Book and Author. Otherwise it will drive you crazy. You can keep the table names plural if you want.
====================================================
Question #3:
When doctrine creates a linking table then it hides it completely. What you need to do is to make your own BookAuthor entity and then set one to many relations from it to Book/Author. At that point you will have full access to it. You can also add additional properties if you want.
Post a Comment for "Doctrine Many-to-many Relations And Onflush Event"