[英]Associations with Doctrine 2
I'm trying make an entity with doctrine that has three associations with other entities 我正在尝试创建一个具有学说的实体,该实体与其他实体具有三个关联
So an Item is associated with: 因此,某项与以下内容相关联:
Here is my attempt: 这是我的尝试:
class Item{
/**
* @ManyToOne(targetEntity="Rssfeed")
*/
protected $rssfeed;
/**
*
* @ManyToMany(targetEntity="Location")
*/
protected $locations;
/**
*
* @ManyToMany(targetEntity="Tag")
*/
protected $tags;
}
Now 现在
How should I change my code to accomplish that? 我应该如何更改我的代码来实现这一目标?
U have to add @JoinColumn with onDelete="CASCADE" for $rssfeed and onDelete="SET NULL" for foreign keys in Location and Tag entities. 您必须为$ rssfeed添加@JoinColumn并为其onDelete =“ CASCADE”以及为Location和Tag实体中的外键添加onDelete =“ SET NULL”。
/**
* @ManyToOne(targetEntity="Rssfeed")
* @JoinColumn(name="rssfeed_id", referencedColumnName="id", onDelete="CASCADE")
*/
protected $rssfeed;
For each association in your Item entity, add onDelete="SET NULL" to the @JoinColumn annotation. 对于Item实体中的每个关联,将onDelete =“ SET NULL”添加到@JoinColumn批注。 Inside your location and tag entities, find the JoinColumn annotations and add onDelete="SET NULL" for the association with "Item". 在您的位置和标记实体中,找到JoinColumn批注,并为与“ Item”的关联添加onDelete =“ SET NULL”。 Under the RssFeed entity, find each @JoinColumn annotation and add onDelete="SET NULL". 在RssFeed实体下,找到每个@JoinColumn注解并添加onDelete =“ SET NULL”。 Note that you can also use Doctrine cascade operations to achieve this (ie cascade={"remove"}, etc; however, it will likely be significantly slower as the operating is not performed at the RDBMS level. 请注意,您也可以使用Doctrine级联操作来实现此目的(例如,级联= {“删除”}等;但是,由于操作不是在RDBMS级别执行的,因此它的运行速度可能会大大降低。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.