是否可以使用确切类型OR null验证实体的属性?换句话说,该属性可以具有精确类型的optinal值.
例如,可以设置属性$ date(\Datetime类型):
/**
* @ORM\Column(type="datetime", nullable=true)
* @Assert\Type("\DateTime")
*/
protected $date;
Run Code Online (Sandbox Code Playgroud)
不要介意nullable=true在@ORM\Column一节,它仅适用于DB-水平,而不是模型验证.
问题是:如果$ date不存在,则错误为:
Expected argument of type "DateTime", "NULL" given