Adding extra field in many_to_many symfony2 relationship

730 views Asked by At

Im looking for a way to handle many_to many relationship in symfony2 with extra field, I have 3 entities : Skill/Training/Skill-Training .Every training should affect some skills and increment the level of those skills. So Skill-Training table is like this (skill_id,training_id,target_level)

In the Form of the Training i want to list all skills and the target level with each skill, so i can choose a skill and add the target level (integer from 1 to 5) that will be affected with this Training. I want to do this in the Add Form of the Training entity.

I use Sonata Admin Bundle To generate my Admin Classes ,i can render the list of skills with the checkbox easly (using type collection , and the option expanded true , multiple true ) but im wondering how to render the extra field target_level in front of each skill in the form of Training ??

I will be very greatful if you help me. Im looking for the solution for 3 days without any progress ... thanks

1

There are 1 answers

1
kozlice On

Here are the similar questions:

Doctrine2: Best way to handle many-to-many with extra columns in reference table

Doctrine 2 and Many-to-many link table with an extra field

TL;DR: Unfortunately, relationships can't have any extra fields. You need to create one more entity, which would have two relations (with Skill and Training entities) and property for target level.