我对具有多对多关系的模型的嵌入形式有疑问。嵌入的表单将正确保存模型,但不会保存多对多关系。
例子:
架构.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
然后我只修改 MotherForm.class.php:
class MotherForm extends BaseMotherForm
{
public function configure()
{
$this->embedForm('child', new ChildForm($this->getObject()->getChildren()));
}
}
和 ChildForm.class.php:
class ChildForm extends BaseChildForm
{
public function configure()
{
unset($this['mother_id']);
}
}
我用学说生成模块:
php symfony doctrine:generate-module frontend mother Mother
放一些颜色数据:
Color:
Color_1:
name: blue
Color_2:
name: red
Color_3:
name: green
Color_4:
name: purple
当我调用 /frontend_dev.php/mother/new 我可以添加一个新的,母亲和孩子的名字被更新,但最喜欢的颜色永远不会被保存......
如果我使用 phpmyadmin 添加颜色和子项之间的关系,然后 /edit 调用。然后正确的颜色在选择的多选中,但我无法编辑它。
这是 Symfony 的错误还是我应该做其他事情?
更新:如果我为模型 Child 生成模块。我可以编辑最喜欢的颜色,但表格不再嵌入......