主义2连接表+额外字段 [英] Doctrine 2 join table + extra fields

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

问题描述

我有两张桌子和一张连接表:工作人员,分类和staff_classification。在连接表中,我有一个额外的布尔字段:'showclassification'。我的注释如下:

  / ** 
* @ManyToMany(targetEntity =Staff,inversedBy =分类)
* @JoinTable(name =staff_classifications,
* joinColumns = {@ JoinColumn(name =staffid,referencedColumnName =id)},
* inverseJoinColumns = { @JoinColumn(name =classificationid,referencedColumnName =id,unique = true)});
* /




  1. 如何添加额外字段'显示分类到连接表?

  2. 如何通过DQL引用该字段?例如。什么查询会得到所有员工的分类,允许显示?

  3. 我将上述注释放在一个类中,另一个是没有@joinTable的@ManyToMany注释吗?例如。 @ManyToMany(targetEntity =Classification)?


解决方案

关系(StaffClassifications),与员工和分类有OneToMany关系。



ManyToMany不允许您拥有任何额外属性,因为连接表不是实体,因此不能有任何属性。


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. How do I add the extra field 'showclassifications' to the join table?
  2. How do I reference the field via DQL? E.g. What query would get all of a staff's classifications that are allowed to be shown?
  3. Do I place the above annotation in one class and a @ManyToMany annotation with no @joinTable in the other? E.g. @ManyToMany (targetEntity="Classification")?

解决方案

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

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

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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆