2012-05-29 166 views
5

我嘗試在Doctrine中使用onFlush事件來堅持一個新的實體,但是當試圖持久化時會導致無限循環。以下是我在做聽衆:堅持新實體onFlush

$countusers = $em->getRepository('DankeForumBundle:NotificationUser')->countNotificationsByDeal($entity); 
if ($countusers > 0) { 
    $notification = new NotificationAction(); 
    $notification->setDeal($entity); 
    $notification->setDatepost(new \DateTime()); 
    $notification->setNotificationtype(NotificationAction::TYPE_TOP_DEAL); 
    // $em is set to EntityManager 
    $em->persist($notification); 
    // $uow ist set to UnitOfWork 
    $uow->computeChangeSet($em->getClassmetadata('Danke\ForumBundle\Entity\NotificationAction'), $notification); 
} 

我知道我會得到一個循環,當我衝在onFlush事件,但我不這樣做!我只計算文檔中說的新變更集。

有人可以告訴問題在哪裏嗎?

編輯:這也許有趣,我敢肯定它的工作有些天了,但我不記得任何更改(我知道不可能是真的;))...

+0

也適用於我,但無法弄清楚爲什麼...我希望這裏有人能幫助我們 – mokagio

回答

3

我有類似的問題與onFlush事件。請更改

$em->persist($notification); 

$uow->persist($notification); 

請試試這個,讓我知道這是現在的工作。