2015-06-05 9 views
8

Quando Sto presentando forma Symfony2 ho ottenuto il seguente errore:Symfony 2 - Entità deve essere gestito o in programma per la rimozione di un singolo calcolo

Entity has to be managed or scheduled for removal for single computation

Che cosa significa questo errore?

Sto utilizzando il modulo che ha lo scopo di aggiungere un nuovo elemento al DB. Ho più relazioni ManyToOne nel modulo.

/** 
    * This code is aimed at checking if the book is choseen and therefore whether any further works may be carried out 
    */ 
    $session = new Session(); 
    if(!$session->get("App_Books_Chosen_Lp")) return new RedirectResponse($this->generateUrl('app_listbooks')); 

    $request = $this->get('request'); 
    $em = $this->getDoctrine()->getManager(); 
    if($item_id != null) 
    { 
     /* THIS CODE IS NOT EXECUTED IN THE GIVEN CASE */ 
    } 
    else 
    { 
     // Add 
     $item = new Items(); 
     $form = $this->createForm(new ItemsType(), $item); 
     $form->add('save', 'submit', array('label' => 'Add item')); 
    } 
    $form->remove('documentid'); 
    $form->remove('book'); 
    $form->handleRequest($request); 
    if ($form->isValid()) { 

     if($item_id != null) 
     { 
      /* THIS CODE IS NOT EXECUTED IN THE GIVEN CASE */ 
     } 
     else 
     { 
/* HERE ERROR OCCURS */ 
      // Add 

      $book = $em->getReference('AppBundle:Books', $session->get("App_Books_Chosen_Lp")); 
      if($book) $item->setBook($book); 
      $doc = $em->getReference('AppBundle:Documents', $doc_id); 
      if($doc) $item->setDocumentid($doc); 
      $em->flush($item); 
      $session = new session(); 
      $session->getFlashBag()->add('msg', 'Item was added.'); 
      $url = $this->generateUrl("app_documents_details", array("id" => $doc_id)); 
      return $this->redirect($url); 
     } 
+0

Grazie per aver ridotto il codice alle filiali in questione !! – Barett

risposta

17

È necessario mantenere la propria entità per consentire a EntityManager di sapere che esiste.

$em->persist($item); 
$em->flush($item); 
Problemi correlati