-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
Entity field saved as json_object instead of json_array #23653
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
Comments
@OkieRazorback thanks for reporting this, but I'm afraid we'd need more information. The reason is that Symfony doesn't persist entities, it's Doctrine who does that. So, where do you think this issue happens? When submitting some info in a form, when handling some data in a request or when executing the Doctrine logic? Thanks! |
This logic comme from the php You should use |
The reason I think this is happening in Symfony is if I output the request data the array is ordered properly (1,2,3) but after it runs through I was able to work around the issue by using |
@HeahDude would you consider this a bug of |
It may come from the ResizeFormListener if this is about a collection field. But we don't have enough information to be sure of what's actually happening. @OkieRazorback could you please create a reproducer for this bug? Thanks! |
Actually it's not a bug, it is expected that on removal the listener keeps the index of each element. So using a transformer as proposed by @jvasseur is half a solution because in your case it has to be a model transformer which does not reapply the changes on the view data if the view is generated after submission (invalid or without redirection). So it must happen in a Not sure this is worth to add such behavior in the core with a proper option like |
closing because of the reasons given by @HeahDude |
Same issue here, I was able to solve the issue adding array_values on entity: $this->propertyWithIssue = array_values($propertyWithIssue); |
When persisting an entity that has had an item removed from the array the data is save as a json_object instead of json_array.
Expected
["item1","item2","item3"]
Actual
{"0":"item1","1":"item2","2","item3"}
This seems to only happen when removing an item from the array and I believe it has to do with the way php handles array indexes. From my debugging it appears that when the array indexes are not sequential (ie
0,2,3
) it is seen as an associative array which causes the data to be persisted as a json_object instead of json_array. The problem does not occur as long as there are no array items or the indexes are sequential.The text was updated successfully, but these errors were encountered: