Symfony Doctrine:一对多关系正在删除父实体

时间:2017-05-24 08:14:17

标签: symfony doctrine-orm one-to-many symfony2-easyadmin

我有父母和子女实体。删除所有子实体后,symfony也会删除我的父实体。我不喜欢这种行为,只要有一些孩子,父母实体就必须存在。这是我父母的代码:

css

这是为了孩子:

.modal-dialog{ 

    top:50% !important;
    position:fixed !important;
}

我不知道该怎么做,我已经花了好几个小时。

它由简单的管理包处理,所以它不会帮助你:

    /**
     * @OneToMany(targetEntity="Gallery", mappedBy="promotion", cascade={"persist", "remove"})
     */
    private $galleries;

    public function __construct() {
        $this->galleries = new ArrayCollection();
    }

    public function getGalleries() {
        return $this->galleries;
    }

    public function addGallery($gallery)
    {
        $gallery->setPromotion($this);
        $this->galleries[] = $gallery;

        return $this;
    }

    public function removeGallery($gallery)
    {
        $gallery->setPromotion(null);
        $this->galleries->removeElement($gallery);
    }

1 个答案:

答案 0 :(得分:0)

尝试删除级联注释。其余的看起来不错。

相关问题