php - ZF2 - Doctrine - Delete an entity persistent -
started working doctrine in zf2 , need delete entity persistence.
$result = $em->getrepository('zmpim\entity\collection')->findoneby(array('id'=>$id)); $products = $result->getproducts(); $this->assertsame(1, count($products)); $this->assertsame(3, count($products[0]->getfields())); $em->remove($result); $em->persist($result); $em->flush($result);
the example in unit test. expect, entity deleted after it. entity , onetomany entities still there.
cu n00n
what looking cascade={"remove"}
. take @ question:
understanding doctrine cascade operations
you define cascade option in association annotation of entity this:
/** * @orm\onetomany(/* ... */ cascade={"remove"}) */
this works every kind of association of course.
doctrine documentation:
in separate unit test, you'd entities metadata check cascade specification of association calling like:
$mapping = $entitymanager->getclassmetadata('zmpim\entity\collection') ->getassociationmapping('products'); $this->asserttrue($mapping['iscascaderemove']);
Comments
Post a Comment