I'm building a REST API with Symfony. Let's say I've got the following Doctrine entity:
class Car {
private $model;
private $make = 'Mercedes';
/** @Assert\NotBlank() **/
private $year;
}
When I try to create a new Car
with an HTTP POST request (REST, no browser), if the request doesn't contain any value for the $make
property, by default the Form::submit()
method nullifies this field in my entity. As I don't want it to do so, I set its clearMissing
argument to false. This works fine except now my @Assert
constraints are not taken into account (as opposed to when clearmissing
is true
). For instance the $year
property doesn't trigger any error if null
, it looks looks like no validation is performed
So I'd like to know if there is a way to have:
- properties with default values on my entity
- plus no field nullification for missing data
- plus @Asserts constraints respected
Note:
I found a two year old issue on Github which describes my problem exactly, but the problem is supposed to be fixed. So it shouldn't be the same as mine...