php - Doctrine 2 ManyToMany cascade -


is possible in doctrine 2 create 2 objects many many related , call persist on 1 of them save both?

user entity:

    /**  * owning side  *  * @manytomany(targetentity="role", inversedby="users", cascade={"persist"})  * @jointable(name="user_roles",  *      joincolumns={@joincolumn(name="user_id", referencedcolumnname="id")},  *      inversejoincolumns={@joincolumn(name="role_id", referencedcolumnname="id")}  *      )  */ public $roles; 

role entity:

    /**  * inverse side  *  * @manytomany(targetentity="user", mappedby="roles")  */ public $users; 

saving:

    $role = new role();      $user = new user();  $user->roles->add($role); $role->users->add($user);  $em->persist($user); $em->flush(); 

it doesn't work , trows error "a new entity found through relationship not configured cascade persist operations: entities\role@0000000004a29c11000000005c48cb75. explicitly persist new entity or configure cascading persist operations on relationship."

you should apply cascade={"persist"} role entity.

not expert on doctrine, think doctrine checks associated entity cascading options.

since cascading persist from users to roles, checks role entity if should persisted cascade.


Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -