Embedding a collection of forms Symfony2 forms with adding and deleting allowed

后端 未结 3 1095
自闭症患者
自闭症患者 2021-02-06 02:31

In Symfony2, if I embed a collection of forms pointing at a many to one relationship in Doctrine and allow adding and deletion, if I delete a record from the beginning, add one

3条回答
  •  不知归路
    2021-02-06 02:42

    One way to pass primary id is to use INDEX BY.

    For example, say I have an entity called Customer and a Customer has several Emails. In my Customer repository class, I can specify my collection to be indexed by Email's primary id.

    $qb->select('c, e')
        ->leftJoin('c.emails', 'e', null, null, 'e.id')
        ->where('c.id = :id');
    

    By doing so, the generated name of the input tag would be

    customer[emails][e.id][fieldName]
    

    Upon submitting the form, Symfony will bind the request values according to the input names.

提交回复
热议问题