New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Identify weird bug with ManyToMany relations #1534
Conversation
I have also encountered this.. currently just made a normalizer for doctrine collection which resets indexes 😞 |
Wow the dirty fix haha, this needs a proper fix I'll investigate! |
Good to know 👍 |
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 |
8e2048d
to
ef1e4fe
Compare
@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: |
ef1e4fe
to
2d1288d
Compare
That's actually good enough IMO! Thanks! I'll keep the test for documentation purpose :). |
i didnt even know that there is a |
But using |
Doctrine does not recommend returning the collection anyway. If you need the matching method you may as well use a repository or add a delegation method to your entity |
Could you point me where I could read about that?:) |
This is a known issue with Doctrine for years, and IIRC it has been marked as won't fix. It also affects FOSRestBundle btw. |
thanks :) |
I didn't make any changes, feel free to merge this to add a test or just close it :). Thanks @backbone87 for pointing me in the right direction! |
Closing as wontfix. |
We should definitely create a doc entry regarding this issue. |
just had to fix this. +1 for a doc 😆 |
Take a
ManyToMany
relation.Add 2 elements, then remove the first one by issuing
PUT
requestsThe third request (when you remove the first one) will give you an
object
instead of anarray
.Simplified Behat suite (available in this PR):
I suspect the denormalization but I might be wrong.