Doctrine Mongodb, no persist of reference documents in an event

LeslieK

New Member
I have an entity Tournament which references many entity participants\[code\]<reference-many field="participants" target-document="Application\Competition\ParticipantBundle\Model\Participant" mapped-by="tournament"><cascade><refresh/><remove/><persist/></cascade></reference-many>\[/code\]I have an event subscribed on preUpdate of the Tournament entity. If the participant type of my tournament changed, I delete the participants and add new ones.I tried the code in my controller and it works.\[code\]//add the right type of participantsfor ($i=1; $i<=$tournament->getSize(); $i++) { $participant = $factory->create(); $participant->setNumber($i); $participant->setName('Player '.$i); $participant->setDiscipline($tournament->getDiscipline()); $participant->setType($tournament->getParticipantType()); $participant->setTournament($tournament); $tournament->addParticipant($participant);}$dm->flush();\[/code\]In my event, tournament is updated but no participant has been added.\[code\]// add the right type of participantsfor ($i=1; $i<=$tournament->getSize(); $i++) { $participant = $factory->create(); $participant->setNumber($i); $participant->setName('Player '.$i); $participant->setDiscipline($tournament->getDiscipline()); $participant->setType($tournament->getParticipantType()); $participant->setTournament($tournament); $tournament->addParticipant($participant);}$tournament->setName('buuugggg');// must call recomputeSingleDocumentChangeSet for the modified document in order for the changes to be persisted.$class = $dm->getClassMetadata(get_class($tournament));$dm->getUnitOfWork()->recomputeSingleDocumentChangeSet($class, $tournament);\[/code\]Is-it possible to persist references entities in an event?
 
Top