Skip to content

[3.0] [Form] Add/remove collection rows in PATCH requests without sending the existing rowsΒ #8301

Closed
@glumb

Description

@glumb

I'm trying to update a form collection item with a PATCH request and or $form->submit($request,false);. Either way, all items are removed from the collection except the new one.

        echo "Items from the database ------------------------------------";
        \Doctrine\Common\Util\Debug::dump($entity->getItems(), 1);

        $form->submit($request,false);

        echo "Items in the form ------------------------------------";
        \Doctrine\Common\Util\Debug::dump($form->get('items')->getData());

        echo "updated items ready to save to database";
        \Doctrine\Common\Util\Debug::dump($entity->getItems(), 1);

I submit the form with modifications for item[0] entity[items][0][description] test 1234.
The output dump is shown below.

Items from the database ------------------------------------
array(2) {
  [0]=>
  string(29) "CoBo\RecipeBundle\Entity\Item"
  [1]=>
  string(29) "CoBo\RecipeBundle\Entity\Item"
}

Items in the form ------------------------------------
array(1) {
  [0]=>
  object(stdClass)#776 (8) {
    ["__CLASS__"]=>
    string(29) "CoBo\RecipeBundle\Entity\Item"
    ["id"]=>
    int(248)
    ["description"]=>
    string(9) "test 1234"
  }
}

updated items ready to save to database
array(1) {
  [0]=>
  string(29) "CoBo\RecipeBundle\Entity\Item"
}

As said, item[1] got removed. I'm not quite sure, if this is the expected behaviour, since a PATCH request should not remove items?!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions