[英]Create schema in Symfony 2 and Doctrine 2 with ON DELETE CASCADE
I have some cross table between User table and Role table. 我在用户表和角色表之间有一些交叉表。 I want to create cascade removing on the database level.
我想在数据库级别创建级联删除。 I have the next annotation:
我有下一个注释:
/**
* @ORM\ManyToMany(targetEntity="Role")
* @ORM\JoinTable(name="user_x_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id")}
* )
* @var ArrayCollection $roles
*/
protected $roles;
But foreign keys have ondelete=restrict and onupdate=restrict after: 但是外键在以下情况下具有ondelete = restrict和onupdate = restrict:
doctrine:schema:update --force
How can I change these values to CASCADE? 如何将这些值更改为CASCADE?
You should try this, don't forget to modify also the cascade on ORM level. 您应该尝试一下,不要忘记在ORM级别上也修改级联。
/**
* @ORM\ManyToMany(targetEntity="Role", cascade={"persist","remove"})
* @ORM\JoinTable(name="user_x_role",
* joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id", onDelete="CASCADE")},
* inverseJoinColumns={@ORM\JoinColumn(name="role_id", referencedColumnName="id", onDelete="CASCADE")},
* )
* @var ArrayCollection $roles
*/
protected $roles;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.