I have a problem with embbed form from Model which has many to many relation. The embedded form will save the model correctly but will not save many to many relations.
Example:
Schema.yml:
Mother:
columns:
name:
type: string(80)
Color:
columns:
name:
type: string(80)
Child:
columns:
mother_id:
type: integer
name:
type: string(80)
relations:
Mother:
class: Mother
local: mother_id
foreign: id
type: one
onDelete: cascade
foreignType: one
foreignAlias: Children
FavoriteColors:
class: Color
refClass: ChildColor
local: child_id
foreign: color_id
onDelete: cascade
foreignAlias: Children
ChildColor:
columns:
child_id:
type: integer
color_id:
type: integer
Then I just modify MotherForm.class.php:
class MotherForm extends BaseMotherForm
{
public function configure()
{
$this->embedForm('child', new ChildForm($this->getObject()->getChildren()));
}
}
and ChildForm.class.php:
class ChildForm extends BaseChildForm
{
public function configure()
{
unset($this['mother_id']);
}
}
I generate the module with doctrine:
php symfony doctrine:generate-module frontend mother Mother
Put some color data:
Color:
Color_1:
name: blue
Color_2:
name: red
Color_3:
name: green
Color_4:
name: purple
When I call /frontend_dev.php/mother/new I can add a new one, name of Mother and Child are updated but favorite color are never saved...
If I add a relation between a color and a child with phpmyadmin and then /edit call. Then the right color is in the multiple select selected, but I can't edit it.
Is it a bug from Symfony or should I do something else ?
UPDATE: If I generate the module for the model Child. I can edit favorite colors but the form is not embedded anymore...