简体   繁体   中英

Symfony 2 Doctrine ODM MongoDB perstist an hydrate document

When i want to persist the $notice document, it save the $contexteUtilObj but it doesn't associat the $contexteUtilObj with the $notice document.

//Controller
$dm = $this->get('doctrine.odm.mongodb.document_manager');
$notice = $dm->getRepository('WikiludoNoticeBundle:Notice')->find($id);
$contexteUtils = array();
$notice->setContexteUtilisations($contexteUtils);
if (count($form['context']) > 0) {
    foreach ($form['context'] as $key => $context) {
        if ($key == 0 and ! $context['valeur']) {
            break;
        }
        if (!$context['valeur']) {
            continue;
        }
        if ($context['id'] and ! is_numeric($context['id'])) {
            $contexteUtilObj = $dm->getRepository('WikiludoNoticeBundle:ContexteUtilisation')->find($context['id']);
        } else {
            $contexteUtilObj = new \Wikiludo\NoticeBundle\Document\ContexteUtilisation();
        }
        $contexteUtilObj->setContexteUtilisation1($context['valeur']);
        $notice->addContexteUtilisations($contexteUtilObj);
    }
}
$dm->persist($notice);
$dm->flush();

...

//Notice Document Structure
/**
 * @MongoDB\ReferenceMany(
 *      targetDocument="Wikiludo\NoticeBundle\Document\ContexteUtilisation",
 *      cascade="all"
 * )
 */
protected $contexteUtilisations;

Sorry i resolve my problem. I must juste do :

$dm->flush($notice);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM