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:

http://doctrine-orm.readthedocs.org/en/latest/reference/working-with-associations.html#transitive-persistence-cascade-operations

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

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -