与Symfony2表单中的属性有很多对很多关系

I have built a many to many relation with attributes between entities. I am quite sure entities are correct but I am struggling with the form.

Here is my db model :

  • User
  • Skill
  • UserSkill (with a rating field)

My goal is to create a User with a form and to be able to add many skill to this user. For each skill, I have to add a rating.

Here is the way I create the form :

$builder->add('userSkill', 'collection', array(
  'entry_type'      => new UserSkillType(),
  'by_reference'    => false,
  'allow_add'       => true,
  'allow_delete'    => true,
  'add_button_text' => 'Add a skill'
));

And here is the error I get :

An exception occurred while executing 'INSERT INTO user_skill (rating, user_id, skill_id) VALUES (?, ?, ?)' with params [9, null, 3]:

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'user_id' cannot be null

Do you know any good link which can show me how to do or do you have a working example ?

Thank you

NB : I have already built Many-to-many relation form but it is the first time I do it with attributes.