Zend framework 如何使用Doctrine2关联将M:1级联设置为null?

Zend framework 如何使用Doctrine2关联将M:1级联设置为null?,zend-framework,doctrine-orm,Zend Framework,Doctrine Orm,有点可疑,请原谅 我想删除一首歌曲: 对于cascade=all,我的1:M关联可以正常工作。例如,与歌曲相关的收视率可能会被删除 我不知道该怎么做。目前,我将这些属性设置为null,然后保留这些属性,然后删除歌曲。专辑和艺术家应该留下来,因为它与其他歌曲相关 摘录: /** * OWNING SIDE * @var My\Entity\Album * @ManyToOne(targetEntity="Album", inversedBy="songs") */ private $alb

有点可疑,请原谅

我想删除一首歌曲:

对于cascade=all,我的1:M关联可以正常工作。例如,与歌曲相关的收视率可能会被删除

我不知道该怎么做。目前,我将这些属性设置为null,然后保留这些属性,然后删除歌曲。专辑和艺术家应该留下来,因为它与其他歌曲相关

摘录:

/**
 * 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;
我希望继续使用关联级联,而不是在db级别。
关于使用$em->remove($song)而不将我的M:1额外持久化为null,有什么建议吗?

我发现它包含以下内容:

在我的歌曲(父)实体中:

这些方法(在存储库中)如下所示:

/**
 * Removes similars with song
 */
public function removeSong($song)
{
    $ratings = $this->getSong($song);
    foreach ($ratings as $rating) $this->getEntityManager()->remove($rating);
    $this->getEntityManager()->flush();
}
在我的类似和评级实体中:

/** @PreRemove */
public function preRemove()
{
    $this->winner = $this->loser = null;
}

我发现它包含以下内容:

在我的歌曲(父)实体中:

这些方法(在存储库中)如下所示:

/**
 * Removes similars with song
 */
public function removeSong($song)
{
    $ratings = $this->getSong($song);
    foreach ($ratings as $rating) $this->getEntityManager()->remove($rating);
    $this->getEntityManager()->flush();
}
在我的类似和评级实体中:

/** @PreRemove */
public function preRemove()
{
    $this->winner = $this->loser = null;
}