本文介绍了Doctrine 2 连接表 + 额外字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个表和一个连接表:staff"、classification"和staff_classification".在连接表中,我有一个额外的布尔字段:'showclassification'.我的注释如下:

I've got two tables and a join table: 'staff', 'classification' and 'staff_classification'. In the join table I've got an extra boolean field: 'showclassification'. My annotation is as follows:

 /**
 * @ManyToMany(targetEntity="Staff", inversedBy="classifications")
 * @JoinTable(name="staff_classifications",
 *  joinColumns={@JoinColumn(name="staffid", referencedColumnName="id")},
 *  inverseJoinColumns={@JoinColumn(name="classificationid", referencedColumnName="id", unique=true)});
 */
  1. 如何将额外的字段showclassifications"添加到连接表中?
  2. 如何通过 DQL 引用字段?例如.什么查询会获得允许显示的所有员工分类?
  3. 我是否将上述注释放在一个类中,而在另一个类中放置一个没有 @joinTable 的 @ManyToMany 注释?例如.@ManyToMany (targetEntity="Classification")?

推荐答案

您需要一个描述关系 (StaffClassifications) 的实体,该实体与员工和分类都具有单对多关系.

You want an entity that describes the relationship (StaffClassifications), which has OneToMany relationships with both staff and classifications.

ManyToMany 不允许你有任何额外"的属性,因为连接表不是一个实体,因此不能有任何属性.

ManyToMany doesn't allow you have any "extra" properties, because the join table is not an entity, and thus can't have any properties.

这篇关于Doctrine 2 连接表 + 额外字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-08 01:41