zend framework - doctrine 2 remove object from relationship array collection -



zend framework - doctrine 2 remove object from relationship array collection -

class lists extends \entities\abstractentity { /** * @id @column(name="id", type="bigint",length=15) * @generatedvalue(strategy="auto") */ protected $id; /** * @manytomany(targetentity="\entities\users\usercomments") * @joincolumn(name="id", referencedcolumnname="id") */ protected $comments; public function getcomments() { homecoming $this->comments; } public function addcomments($comment) { $this->comments->add($comment); } public function deletecomments(\entities\users\comments $comments) { $this->comments->removeelement($comments); } /** @preupdate */ public function updated() { //$this->updated_at = new \datetime("now"); } public function __construct() { $this->entry = new \doctrine\common\collections\arraycollection(); } }

i have many many table create doctrine.. can manage add together comments table by:

$getlist = $this->_lis->findoneby((array('userid' => $userid))); $getcomments = $this->_doctrine->getreference('\entities\users\comments', $commentid); $getlist->addcomments($getcomments); $this->_doctrine->flush();

but cant delete... tried: removeelement no joy.. told me can unset soemthing in array collection, dont it...

you can utilize simple php "unset()" on arraycollection element. best place define new method in entity class.

here illustration removes elements arraycollection property:

/** * goes entity class * refers property entity::widget * @return $this */ public function removeallwidgets() { if ($this->widget) { foreach ($this->widget $key => $value) { unset($this->widget[$key]); } } homecoming $this; }

you define entity method remove single element:

/** * goes entity class * @param int $elementid * @return $this */ public function removeonewidget($elementid) { if (isset($this->widget[$elementid])) { unset($this->widget[$elementid]); } homecoming $this; }

zend-framework doctrine doctrine2

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -