I was wondering why my CollectionType doesn't call the custom addCollection function that sets the foreign key to $this (and thus the next time the collection is empty).
Then i found out about 'by_reference' but it didn't fix the problem but instead made it worse.
in the form i simply do:
$builder->add('myprop', CollectionType::class, [
'label' => false,
'entry_type' => MyEntityType::class,
'entry_options' => [
'label' => false,
'new' => $new,
],
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false, // instead of not calling add it now throws an error
]);
and the MyEntityType is just another type with data_class set and fields for it
It seems it is using the Doctrine Proxies instead of my Entity i pass into the FormBuilder as i get the error message:
Could not determine access type for property "myprop" in class "Proxies\__CG__\App\Entity\MyEntity": Neither the property "myprop" nor one of the methods "addMyprop()"/"removeMyprop()", "addMyprop()"/"removeMyprop()", "setMyprop()", "Myprop()", "__set()" or "__call()" exist and have public access in class "Proxies\__CG__\App\Entity\MyEntity".
using newest Symfony 4.3 (4.3.5)
The issue was not in the FormBuilder but instead in the Entity as it was imported using plural names and the Symfony name generator tried to call the singular method but only the plural one existed...