Symfony Doctrine Cascade已删除

时间:2016-02-09 10:18:38

标签: php symfony doctrine-orm

我有表Users和CodeProjectNotificationLater并使用

 * @Gedmo\SoftDeleteable(fieldName="deletedAt")

和关系一个用户To Many CodeProjectNotificationLater,当我删除Users(设置deletedAt)时,我的CodeProjectNotificationLater没有设置deletedAt,但必须是。因为我使用级联持久和删除。但在用户中我还有一个现场开发人员,但另一个关系 - 一个开发人员的许多用户和我删除用户(设置deletedAt)时我的开发人员也删除了(设置了deletedAt)。如何级联删除的CodeProjectNotificationLater?

用户实体

    /**
 * @ORM\OneToMany(targetEntity="CodeProjectNotificationLater", mappedBy="users", cascade={"persist", "remove"})
 */
public $notification_later;

    /**
 * @ORM\ManyToOne(targetEntity="Artel\ProfileBundle\Entity\Developer", inversedBy="user", cascade={"persist", "remove"}, fetch="EAGER")
 * @ORM\JoinColumn(name="developer_id", nullable = true, referencedColumnName="id")
 * @Expose()
 * @Groups({"get_team_developer", "get_developer_by_id"})
 */
protected $developer;

和CodeProjectNotificationLater实体

    /**
 * @ORM\ManyToOne(targetEntity="Users", inversedBy="notification_later", cascade={"persist"})
 * @ORM\JoinColumn(name="user_id", nullable = true, referencedColumnName="id")
 */
protected $users;

开发者实体

/**
 * @ORM\OneToMany(targetEntity="Artel\ProfileBundle\Entity\Users", mappedBy="developer",  cascade={"persist", "remove"})
 * @Expose()
 * @Groups({"for_project", "for_all_projects", "for_project_bit"})
 */
protected $user;

更新

我尝试添加orphanRemoval = true但仍然在表CodeProjectNotificationLater中删除了空

    /**
 * @ORM\OneToMany(targetEntity="CodeProjectNotificationLater", mappedBy="users", cascade={"persist", "remove"}, orphanRemoval=true)
 */
public $notification_later;

1 个答案:

答案 0 :(得分:0)

<强>解决

    /**
 * @ORM\OneToMany(targetEntity="CodeProjectNotificationLater", mappedBy="users", orphanRemoval=true)
 */
public $notification_later;

在DB中删除了明确

如果在CodeProjectNotificationLater中使用

 * @Gedmo\SoftDeleteable(fieldName="deletedAt")
DB中的

在deletedAT中有数据