symfony - Doctrine MongoDB ODM do not change state of referenced object -
i'm using symfony2 doctrinemongodb bundle. made service receives informations in json format (objects).
the object i'm sending got property referencing object in different collection in database.
changing reference works. in case send field, "title" objectb - sets title new value in database. how can prevent this?
i want set new reference, no manipulation on object ever.
here code (shortened)
class fun{ /** * @mongodb\id(strategy="auto") */ private $id; /** @mongodb\embedmany(targetdocument="jokeembedded", strategy="set") */ private $jokes = array(); } class jokeembedded { /** * @mongodb\referenceone(targetdocument="jokepattern", cascade={"persist"}) */ private $ref; /** * @mongodb\string */ private $title; } class jokepattern { /** * @mongodb\id(strategy="auto") */ private $id; /** * @mongodb\string */ private $title; }
i'm sending following json service: (json represents objetclass fun)
[{"id":"1","jokes":[{"ref":{"id":"222", "title":"new title"}]]
my question now, how ignore new given "title" reference want set? want have new reference in db set id 222. nothing more.
any great! thank you!
edit:
this code handles json input
$request = $this->getrequest(); //get json-data $data = $request->getcontent(); $funs = $this->get('serializer')->deserialize( $data, 'arraycollection<acme\funbundle\document\fun>', 'json' ); //create documentmanager $dm = $this->get('doctrine_mongodb')->getmanager(); foreach ($funs $obj) { //save db $dm->persist($obj); } $dm->flush();
i managed deserialization context , list annotation within jms serializerbundle.
greetings :)
Comments
Post a Comment