symfony - Sonata Admin sonata_type_collection not remove child entity -


i have news entity "one many" association image entity:

class noticia  {      function __construct()     {         $this->images = new arraycollection();     }      /**      * @orm\onetomany(targetentity="imagemnoticia", mappedby="noticia", cascade={"all"}, orphanremoval=true)      */     private $images;      public function removeimage(imagemnoticia $imagem) {         if ($this->images->contains($imagem) {             $this->images->removeelement($imagem);         }         $imagem->setnoticia(null);          return $this;     } } 

and admin class:

class noticiaadmin extends admin {     protected function configureformfields(formmapper $formmapper)     {          $formmapper              ->add('images', 'sonata_type_collection',                    array(                       'by_reference' => false,                       'required' => false,                    ), array(                       'edit' => 'inline'                       'inline' => 'table'                   )               );     } } 

inserting , updating images works perfectly.

when mark "delete" in image on embeded form , save entity association field removed imagemnoticia entity entity not removed

could tell me how solve problem?

ps: in noticiaadmin have:

public function preupdate($object) {     foreach ($object->getimagens() $imagem) {         $imagem->setnoticia($object);     }     parent::preupdate($object); } 

and imagemnoticiaadmin is:

class imagemnoticiaadmin extends admin {      /**      * @param formmapper $formmapper      */     protected function configureformfields(formmapper $formmapper)     {         $imagemnoticia = $this->getsubject();         if ($imagemnoticia) {             $formmapper->add(                 'file',                 'liip_imagine_image',                 [                     'image_path' => $imagemnoticia->getwebpath(),                     'image_filter' => 'noticia_thumb',                 ]             );         } else {             $formmapper->add(                 'file',                 'file'             );         }         $formmapper             ->add(                 'flag',                 'choice',                 [                     'choices' => imagemnoticia::getflags(),                     'label' => 'tipo'                 ]             )             ->add(                 'legenda',                 null,                 [                     'required' => false,                 ]             );     }  } 

you can try using annotation specify column referenced noticia id need deleted :

/**  * @orm\onetomany(targetentity="imagemnoticia", mappedby="noticia", cascade={"all"}, orphanremoval=true)  * @orm\joincolumn(name="noticia_id", referencedcolumnname="id", ondelete="cascade")  */  private $images; 

Popular posts from this blog