<p dir="auto">My problem might be related to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="4885817" data-permission-text="Title is private" data-url="https://github.com/symfony/symfony/issues/4492" data-hovercard-type="issue" data-hovercard-url="/symfony/symfony/issues/4492/hovercard" href="https://github.com/symfony/symfony/issues/4492">#4492</a>, however now appeared in Symfony v2.7.3:<br>
Reordering of form collections using AJAX submits does not work correcly.</p>
<p dir="auto">I have an entity "Meeting", which consists of a collection of "Topics". When reordering the topics, the integer field "position" is re-assigned using javascript based on the current ordering.</p>
<p dir="auto">When starting, the collection of topics is as follows:</p>
<p dir="auto">topic[0] : topic ZERO, position 0<br>
topic[1] : topic ONE, position 1</p>
<p dir="auto">Now I switch the order (using jQuery), it looks as follows:<br>
topic[1] : topic ONE, position 0<br>
topic[0] : topic ZERO, position 1</p>
<p dir="auto">Now I save this state to the database using AJAX, meaning that in the browser (DOM) nothing changes.</p>
<p dir="auto">Now I switch the order again, it looks exactly as in the beginning:<br>
topic[0] : topic ZERO, position 0<br>
topic[1] : topic ONE, position 1</p>
<p dir="auto">Now I save again using AJAX (no visible change in the browser).</p>
<p dir="auto">When I reload the page, however, something strange appears:<br>
topic[1] : topic ZERO, position 0<br>
topic[0] : topic ONE, position 1</p>
<p dir="auto">-&gt; The order of topics is not switched but only their content reassigned to the new position, which leads to the situation that the topic's content is changed which should definitely not happen.<br>
-&gt; If I reload after the first saving (meaning standard POST submit with page reload instead of AJAX), everything is fine in the end.</p>
<p dir="auto">What's wrong here?<br>
Thanks a lot!</p>
<p dir="auto">Symfony default behaviour for handling reordering in collection type is wrong.</p>
<p dir="auto">When you reorder to items saved in database as:</p>
<p dir="auto">id: 56, name: first, order: 0<br>
id: 57, name: second, order: 1</p>
<p dir="auto">After changing they positions I receive:</p>
<p dir="auto">id: 56, name: second, order: 0<br>
id: 57, name: first, order: 1</p>
<p dir="auto">Instead of:</p>
<p dir="auto">id: 56, name: first, order: 1<br>
id: 57, name: second, order: 0</p>
<p dir="auto">Last occurrence at version 2.0.15</p>