Symfony2 - 表单收集 delete_empty 失败

Symfony2 - form collection delete_empty fails

我有一个嵌入式表单集合字段。 Parent是反面,child(内嵌)是拥有面。我想动态允许 adding/removing children。添加作品,也删除作品(在 orphanRemoval=true 的帮助下)。当我将 child 表格留空时,我得到:

An exception occurred while executing 'INSERT INTO child
(content, completed, parent_id, created_by) VALUES (?, ?, ?, ?)'
with params [null, 0, 30,  8]: Column 'content' cannot be null

内容字段是唯一呈现的字段。该字段根本不应该保留,因为 'delete_empty' 和 'allow_delete' 都在字段类型中设置。 知道为什么会这样吗?

编辑:

我从实体中删除了所有元数据以确保它确实是空的。 Doctrine 尝试插入 (null,null,null,null).

我已经设法解决了这个问题。我在 createForm 方法中添加了空子。逻辑如下:

编辑操作:

$parent = $em->getRepository('AppBundle:parent')->find($id);
$editForm->createEditForm($parent)

创建编辑表单方法:

public function createEditForm(Parent $parent){
    $child = new Child();
    $parent->setChild($child);
    $form = $this->createForm(...)

修复:

在创建表单之前,需要在编辑操作中添加子项(因此传递给表单创建的实体已经有空实体)。