Description
Referring to #9998.
Using symfony/form:2.8.7
Context is a REST API so a HTML form is not an option. But I want to bind the data passed to the API through our custom form type. The form type's data is based on a Doctrine entity. I have the entity that sets a default property of $published = true
(along with others). I have various validations defined in the entity's loadValidatorMetadata
.
Because it's a REST API, I'm binding the data like this
$data = $request->request->all();
$form->submit($data, 'PATCH' !== $method);
However, on POST for a new entity, I'm screwed no matter what $clearMissing
is set to. If $clearMissing
is true and the defaulted values are not included in the request, validation works but I end up with SQL errors because published cannot be null (it's not setting the Entity's default). If I set it to false, then validation fails all together.
The only way I'm thinking I'm going to be able to get around this, is to add methods to dump the entity to an array then merge that with the submitted data - which is not a very cool to do it. Although suggestions would be awesome!
Thanks,
Alan