php - Symfony2 duplicates collection entities when form index is missing -


i using symfony 2 , form component manage relations.

$builder->add('locations', 'collection', array(     'type' => new locationtype(),      'options' => array("em" => $this->em),      "allow_add" => true,      "by_reference" => false,      "allow_delete" => true,      "delete_empty" => true )); 

i use many 2 many relation fields, use many-to-one , one-to-many

it works want. new entities can created. delete entities, provide ajax function removes item db , deletes corresponding html part of form.

when have 2 entities in collection, delete first 1 , not reload form, form has 1 entity element left. 1 has index 1 , not 0. when submit form, have last entity duplicated. not want!

the problem occurs when delete first location, when there "index gap".

how can avoid this? there option?

found solution.

in thr pre_bind event this:

$data["locations"] = array_values($data["locations"]); 

this removes gaps array


Comments

Popular posts from this blog

javascript - oscilloscope of speaker input stops rendering after a few seconds -

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -