Closed ossinkine closed 3 years ago
cc @VincentLanglet
Thanks for the reproducer, I will try to find some time to look at it.
It tooks me some hours to debug this.
Let's say we have the parent has the collection:
[0] => Child
When we add one in the admin, by using addInstance
in the Admin Type (with reference false), we had
[0] => Child
[1] => New Child
Then when submitting
[0] => Child
// The key 1 is removed since it's not the same reference than the NewChild added.
[2] => New Child
And the form error was affected to the key 1.
But with reference true, when submitting we have
[0] => Child
[1] => New Child
So there is no issue with the form error, and we can use addInstance
.
It important to notice that using reference => false
in your case, fix your issue: I can create parent with child.
So if reference => false
is used, setObject
seems to be the correct method.
And if reference => true
is used, addInstance
seems to be the correct method.
Now the question is: Does the AdminType is able to know the option passed to the CollectionType ?
I started a draft PR https://github.com/sonata-project/SonataAdminBundle/pull/6438
I will also need to create a PR on our persistence bundle.
Environment
Sonata packages
Symfony packages
PHP version
Subject
After update
sonata-project/admin-bundle
3.71.1 to 3.75.0 I've got a regression issue. Admin which has children forms does not associate the entities. After couple of hours of debugging I've discovered the issue introduced in #6171.Steps to reproduce
There is a reproducer here https://github.com/ossinkine/sonata-admin-reproducer-6426
Expected results
Open parent object admin in the reproducer and try to create a parent object with a child object and save. No errors expected.
Actual results
There is an error
SQLSTATE[23000]: Integrity constraint violation: 19 NOT NULL constraint failed: child_object.parent_object_id
because the child object does not associated with a parent object.