0

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.

1
  • It might be helpful if you provided some code where you show in what situation you want to access the data. Commented Aug 24, 2015 at 7:30

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, but I do not want to change the structure of the database. I think even a little common a many to many with extra fields, must be accessible by an entity that field. I found the folowing,doctrine-orm.readthedocs.org/en/latest/tutorials/… but I have to link the company with an ORM XML to work and can not.
@JSGarcia: No way, it's not want you want to do or not, is the only possible way groups.google.com/forum/#!topic/doctrine-user/0dh8lgUudvc
I read that with an ORM and an entity set up correctly, pointing out the many to one relationships directly, instead of many to many, you could get. I not have much idea, but I do not think anything too surprising that an N:M relationships may contain additional information. Anyway I left the step performing consultation with native SQL directly to the database, when I have time I will fight again with this to get let correctly. A greeting :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.