Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Identify weird bug with ManyToMany relations #1534
Add 2 elements, then remove the first one by issuing
The third request (when you remove the first one) will give you an
Simplified Behat suite (available in this PR):
I suspect the denormalization but I might be wrong.
I would almost say that this is a bug in doctrine. If I have a too-many relation with no IndexBy then it should be a classical list and lists can not have holes.
edit: one could argue that this is a known limitation of doctrine collections and the
@backbone87 It's just that when removing the value at index 0 the ArrayCollection starts at 1.
Also, it may be considered as a symfony bug because when you have
Anyway, I found a proper fix where we recreate the array we just keep a zero-based index instead of using the one provided by the loop (because it can be a key).
I dont like this approach to fix this. Index maps are a thing in JSON-LD and this is the only way to use them currently. https://json-ld.org/spec/latest/json-ld/#data-indexing
php arrays are ordered maps. If you dont make sure they satisfy list/array constraints then you will ofc not get an array in JSON. Using $collection->removeElement($x) may cause these constraints to be violated. So either we request a change in doctrine so that collection automatically reindexes collections without IndexBy or you solve this in the model: