Forms Symfony2表格集合don';不要检查身份证

Forms Symfony2表格集合don';不要检查身份证,forms,rest,symfony,collections,Forms,Rest,Symfony,Collections,我不知道这是否是一个配置问题,也不知道它是否按预期工作,因为我没有正确使用它。但是当我发送一个包含实体B集合的实体a的PUT请求时,方法bind试图覆盖实体B的属性 例如: 获取实体A: { id : 1, name : "test", collection : [ 0 : { id : 2, name : "Entity B - 2", line : 0, property : "stuff" }, 1 : { id : 3, name : "Entity

我不知道这是否是一个配置问题,也不知道它是否按预期工作,因为我没有正确使用它。但是当我发送一个包含实体B集合的实体a的PUT请求时,方法bind试图覆盖实体B的属性

例如:

获取实体A:

{ 
  id : 1,
  name : "test",
  collection : [
      0 : { id : 2, name : "Entity B - 2", line : 0, property : "stuff" },
      1 : { id : 3, name : "Entity B - 3", line : 1  }
  ]
 }
放置实体A:(从集合中删除了实体B id 2)

结果:

{ 
  id : 1,
  name : "test",
  collection : [
      0 : { id : 2, name : "Entity B - 3", line : 0, property : "stuff" }
  ]
 }
配置:

实体a

     /**
     * @ORM\OrderBy({"line" = "ASC"})
     * @ORM\OneToMany(targetEntity="entityB", mappedBy="entityA", cascade= { "persist", "remove"})
     */
     private $collection;

     public function addCollection($entityB)
     {
          $this->collection[] = $entityB;
          $lines->setEntityA($this);

          return $this;
      }

     public function removeCollection($entityB)
     {
         $this->collection->removeElement($entityB);
         $lines->setEntityA(null);
      }
EntityB

     /**
      * 
      * @ORM\ManyToOne(targetEntity="entityA", inversedBy="collection")
      */
      private $entityA;
控制器

    $form = $this->createForm(new $entityAType(), $entity);
    $form->bind($request);

    if ($form->isValid()) {
        $em = $this->getDoctrine()->getManager();
        $em->persist($entity);
        $em->flush();
    }
表格

    ->add('collection', 'collection', array(
                                        "type" => new entityBType,
                                        'allow_add' => true,
                                        'allow_delete' => true,
                                        'by_reference' => false,
                                        'cascade_validation' => true,
                                    ))

我通过使用事件监听器来解决我的问题,该监听器对表单子项进行重新排序,以匹配resquest的id

    ->add('collection', 'collection', array(
                                        "type" => new entityBType,
                                        'allow_add' => true,
                                        'allow_delete' => true,
                                        'by_reference' => false,
                                        'cascade_validation' => true,
                                    ))