dongying3744 2015-01-21 06:06
浏览 43

Doctrine,Typo3 Flow:无法删除级联工作

I have a model which gives me an error when if i try to delete the entry from the database (due to constraint violation) .

The error message is:

An exception occurred while executing 'DELETE FROM pits_docmanager_domain_model_role WHERE id = ?' with params [2]: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`flow_db_pits_doc_manager`.`pits_docmanager_domain_model_role_role_accesspoints_join`, CONSTRAINT `FK_54B164455C544054` FOREIGN KEY (`docmanager_role`) REFERENCES `pits_docmanager_domain_model`)

#23000: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`flow_db_pits_doc_manager`.`pits_docmanager_domain_model_role_role_accesspoints_join`, CONSTRAINT `FK_54B164455C544054` FOREIGN KEY (`docmanager_role`) REFERENCES pits_docmanager_domain_model\)

And in my entities i have (role.php)

/**
 * @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\AccessPoint> $role_accessPoints
 * @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\AccessPoint",cascade={"remove"})
 * @ORM\JoinTable(name="role_accesspoints",
 * joinColumns={@ORM\JoinColumn(name="access_point_id",referencedColumnName="id")},
 * inverseJoinColumns={@ORM\JoinColumn(name="role_id",referencedColumnName="id")})
 */
protected $role_accessPoints;

and on the other file (accesspoints.php)

/**
 * @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\Role> $accessPoint_roles
 * @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\Role",cascade={"all"})
 */
protected $accessPoint_roles;

even tho i have the cascade option set in the property am still not able to remove that entry.

Edit: What i am trying to achieve is that..

Consider i have 2 models (roles and accesspoints). if i delete a role, i need to be able to delete that role and the corresponding data related to that in the join table (and want to keep the data in accesspoints untouched)

Edit 2: Fixed (removed all the options from the cascade param and it worked)

/**
 * @var \Doctrine\Common\Collections\Collection<\Pits\DocManager\Domain\Model\AccessPoint> $role_accessPoints
 * @ORM\ManyToMany(targetEntity="\Pits\DocManager\Domain\Model\AccessPoint",cascade={})
 * @ORM\JoinTable(name="role_accesspoints",
 * joinColumns={@ORM\JoinColumn(name="access_point_id",referencedColumnName="id")},
 * inverseJoinColumns={@ORM\JoinColumn(name="role_id",referencedColumnName="id")})
 */
protected $role_accessPoints;
  • 写回答

1条回答 默认 最新

  • douyu7879 2015-03-19 07:43
    关注

    try this it will automaticaly remove enries from mm table on deletion result

    /**
     * Result organisation reletion(in Result model)
     *
     * @var \Doctrine\Common\Collections\Collection<\WIND\Alertregistration\Domain\Model\Organization>
     * @ORM\ManyToMany(cascade={})
     * @ORM\Column(nullable=true)
     * @ORM\JoinTable(joinColumns={@ORM\JoinColumn(onDelete="cascade")})
     */
    protected $resultOrgRelation;
    
    评论

报告相同问题?

悬赏问题

  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了