简体   繁体   English

在学说中多对多的实体(symfony2)

[英]Entity many to many in doctrine (symfony2)

I have a table in my database (MySQL) that relates a few hotels with categories. 我的数据库(MySQL)中有一个表,该表将一些酒店与类别相关联。 It is a part table which links the hotels and the categories table since a hotel can belong to many categories and vice versa. 这是一个部分表,它链接酒店和类别表,因为酒店可以属于许多类别,反之亦然。 In the same table I have a field with additional information ( an integer with dimension 1 ). 在同一张表中,我有一个带有附加信息的字段( 维度为1的整数 )。

When generating entities with Symfony console, classes of hotels and categories contain an array of objects of the other entity is created. 当使用Symfony控制台生成实体时,酒店类和类别包含创建另一个实体的对象数组。 That is, from hotels to access the categories to which it belongs and from the categories access to all hotels that have it. 也就是说,从酒店访问它所属的类别,从类别访问所有拥有它的酒店。

The problem is not how I access the additional field to display additional information, as no intermediate entity that view or to invoke. 问题不是我如何访问附加字段以显示附加信息,因为没有中间实体可以查看或调用。

If someone could help me out, I would be very grateful. 如果有人可以帮助我,我将非常感激。

Greetings and thank you. 问候和谢谢。

You have to split the relationship from 您必须将关系从

Hotel --> ManyToMany <-- Category

into

Hotel --> OneToMany <-- HotelCategory --> ManyToOne <-- Category

as a relation with attributes is, indeed, a new entity. 与属性的关系确实是一个新实体。

Into HotelCategory now you can add that attribute. 现在可以在HotelCategory中添加该属性。

Please, pay attention, when you create a new form you need to include HotelCategory and so additional work could be necessary. 请注意,创建新表单时需要包括HotelCategory ,因此可能需要其他工作。

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

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