php - Associated entity not merged correctly -


i have 2 associated entities this:

class solicitation {     <some fields>     /**      * @var \user      *      * @orm\manytoone(targetentity="user", fetch="eager", inversedby="solicitation")      * @orm\joincolumns({      *   @orm\joincolumn(name="id_user", referencedcolumnname="id_user", nullable=false)      * })      * @orderby({"nome" = "asc"})      */     private $user;     <more fields> } 

i don't want cascade operations. problem when try merge existing user before persisting solicitation, this:

$em = $this->getdoctrine()->getmanager(); if (!(\doctrine\orm\unitofwork::state_managed === $em->getunitofwork()->getentitystate($solicitation->getuser()))) {     $em->merge($solicitation->getuser()); } $em->persist($solicitation); 

...it won't change user unitofwork state "managed". i`ts still "detached" , receive , error on saving.

it took me whole day find

$em->merge($solicitation->getuser())  

doesn't change original entity, returns menaged entity. correct is:

$solicitation->setuser($em->merge($solicitation->getuser())); 

then persist solicitation. made question in case else needs this.


Comments

Popular posts from this blog

javascript - How to synchronize the Three.js and HTML/SVG coordinate systems (especially w.r.t. the y-axis)? -

javascript - How do I find how many occurences are there of a highlighted string, and which occurence is it? -

java - Reading data from multiple zip files and combining them to one -