zend framework - How to set M:1 cascade to null using Doctrine2 associations? -
zend framework - How to set M:1 cascade to null using Doctrine2 associations? -
q bit dubious, pardon that.
i want remove song enitity:
my 1:m associations works fine cascade = all. e.g. ratings associated song can deleted.
my m:1 don't know how do. i'm setting properties null, persist properties, remove song. e.g album , artist should stay, it's associated other songs.
excerpt:
/** * owning side * @var my\entity\album * @manytoone(targetentity="album", inversedby="songs") */ private $album; /** * inversed side * @var doctrine\common\collections\arraycollection * @onetomany(targetentity="similar", mappedby="songa", cascade={"all"}) * @orderby({"id" = "desc"}) */ private $similarsa;
i wish maintain using association cascading , not on db level. advice on using $em->remove($song) without persisting of m:1 nulls?
i found following:
in song (parent) entity:
/** @preremove */ public function preremove() { $em = \zend_registry::get('doctrine')->getentitymanager(); $em->getrepository('my\entity\similar')->removesong($this); $em->getrepository('my\entity\rating')->removesong($this); }
those methods (in repository) like:
/** * removes similars song */ public function removesong($song) { $ratings = $this->getsong($song); foreach ($ratings $rating) $this->getentitymanager()->remove($rating); $this->getentitymanager()->flush(); }
and in similar , rating entites:
/** @preremove */ public function preremove() { $this->winner = $this->loser = null; }
zend-framework doctrine2
Comments
Post a Comment