级联删除不工作.cascade = {“删除”}

时间:2016-02-09 13:33:27

标签: doctrine-orm cascade

我正在使用Doctrine 2.我有一个实体,我自己加入。连接中的两列是:

/**
 * @ORM\ManyToOne(targetEntity="Entities\wall_post", inversedBy="shared_wallpost")
 * @ORM\JoinColumn(name="wall_post_id", referencedColumnName="id")
 */
private $shared_from_wallpost;

/**
 * @ORM\OneToMany(targetEntity="Entities\wall_post", mappedBy="shared_from_wallpost", cascade={"remove"})
 */
private $shared_wallpost;
  

让我们说有两个帖子:一个id = 1001秒id = 1002(有   wall_post_id = 1001)

     

现在我想删除1001时,发布时使用wall_post_id 1001获取   删除。

为此我使用cascade = {“remove”}但它不起作用。 我的删除wallpost对象的查询:

//Removing record from table.

    $qb_1 = $em->createQueryBuilder();
                $qb_1->delete('\Entities\wall_post', 'wp');
                $qb_1->where( 'wp.id  = ?1' );
                $qb_1->setParameter('1', $wallpost_id );
                $qb_1->getQuery()->execute();
                $em -> flush();

1 个答案:

答案 0 :(得分:0)

对于cascade = {“删除”} 我们必须使用:

[ServiceContract]
public interface IService
{
    [OperationContract]
    (ServiceStatus) Initialize();

    [OperationContract]
    (ServiceStatus, Settings) GetSettings();

    [OperationContract]
    (ServiceStatus) SetSettings(Settings settings);

    [OperationContract]
    (ServiceStatus, bool) SettingsAccepted();
}

我用过:

$em->remove($wallpost_obj);
            $em->flush();

现在级联删除工作正常。