简体   繁体   English

教义2多对多连接表,映射?

[英]Doctrine 2 Many to Many with join table, mapping?

I'm trying to figure out the correct way to map my three entities together. 我正在尝试找出将三个实体映射在一起的正确方法。 I have a "HouseType", a "Resource" and a HouseType can have multiple Resources (with an integer indicating how many of that resource they have). 我有一个“ HouseType”,一个“ Resource”和一个HouseType可以有多个资源(一个整数表示它们拥有多少资源)。 So I have three tables, the house_type, resource and house_type_resource (with house_type_id, resource_id, and num). 所以我有三个表,house_type,resource和house_type_resource(带有house_type_id,resource_id和num)。

I can't figure out what type of association mapping I should do. 我不知道应该做什么类型的关联映射。 I'm reading this page: http://docs.doctrine-project.org/en/latest/reference/association-mapping.html but I don't see one that's like mine, where I have a third entity to represent the join table, because it has a specific property that needs to be included (the num). 我正在阅读此页面: http : //docs.doctrine-project.org/en/latest/reference/association-mapping.html但我看不到像我这样的人,在这里我有第三个实体来代表联接表,因为它具有需要包含的特定属性(数字)。 It's sort of like the "Many-To-Many, Unidirectional" but I need that third Entity mapped in there. 有点像“多对多,单向”,但我需要在那里映射第三个实体。 I see the note at the end about doing an Association class but I don't see any more info on that. 我在末尾看到了有关进行关联类的说明,但是我没有看到任何更多信息。

Once you start adding extra columns, Doctrine stops treating it as a pure many-to-many relationship because there is extra data, and this data should be managed with an entity. 一旦开始添加额外的列,Doctrine就会停止将其视为纯多对多关系,因为存在额外的数据,并且应该使用实体来管理此数据。 You should create a new entity called HouseTypeResource , then create one-to-many relationships with this inside your HouseType and Resource entities. 您应该创建一个名为HouseTypeResource的新实体,然后在HouseTypeResource实体中与此建立一对多关系。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM