Php ZF2-条令-删除实体

Php ZF2-条令-删除实体,php,zend-framework2,Php,Zend Framework2,开始使用ZF2中的条令,需要从持久性中删除实体 $result = $em->getRepository('zmpim\Entity\Collection')->findOneBy(array('id'=>$id)); $products = $result->getProducts(); $this->assertSame(1, count($products)); $this->assertSame(3, count($produc

开始使用ZF2中的条令,需要从持久性中删除实体

$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);
这个例子是在一个单元测试中。我希望,实体在它之后被删除。但实体和一些单一实体仍然存在


cu n00n

您要查找的是
cascade={“remove”}
。看看这个问题:

在实体的关联注释中定义级联选项,如下所示:

/**
 * @ORM\OneToMany(/* ... */ cascade={"remove"})
 */
这当然适用于各种联想

条令文件:

在一个单独的单元测试中,您可以通过调用以下命令来获取实体元数据,以检查关联的级联规范:

$mapping = $entityManager->getClassMetadata('zmpim\Entity\Collection')
    ->getAssociationMapping('products');
$this->assertTrue($mapping['isCascadeRemove']);

尝试过,很高兴测试映射,但它没有失败。这似乎是正确的。它不是删除产品集合作为成员的实体。。。