简体   繁体   中英

Entity many to many in doctrine (symfony2)

I have a table in my database (MySQL) that relates a few hotels with categories. 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 ).

When generating entities with Symfony console, classes of hotels and categories contain an array of objects of the other entity is created. 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.

Please, pay attention, when you create a new form you need to include HotelCategory and so additional work could be necessary.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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