You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since make:entity generates methods responsible of the association management (add and remove), would'nt be a good idea to "protect" this behavior by returning an array of the values instead of leaking the internal collection ?
Indeed, misuse of this collection can create confusion for some. e.g. this code will not cause a database update : $foo->getBars()->remove($baz);
But using ->getValues() instead could avoid well known serialization issues after a collection element removal (doctrine does not reindex the array, so a serialization to json could produce an object instead of an array) : this is what Api Platform recommends on its documentation : https://api-platform.com/docs/core/serialization/#collection-relation-using-doctrine
The text was updated successfully, but these errors were encountered:
Since make:entity generates methods responsible of the association management (add and remove), would'nt be a good idea to "protect" this behavior by returning an array of the values instead of leaking the internal collection ?
Indeed, misuse of this collection can create confusion for some. e.g. this code will not cause a database update :
$foo->getBars()->remove($baz);
Here, the doctrine documentation suggests to use ->toArray()
https://www.doctrine-project.org/projects/doctrine-orm/en/3.3/reference/working-with-associations.html#association-management-methods
But using ->getValues() instead could avoid well known serialization issues after a collection element removal (doctrine does not reindex the array, so a serialization to json could produce an object instead of an array) : this is what Api Platform recommends on its documentation :
https://api-platform.com/docs/core/serialization/#collection-relation-using-doctrine
The text was updated successfully, but these errors were encountered: