I have a document with the following field in Symfony / Mongo document definition:
/**
* @MongoDB\String
* @Assert\NotEmpty
* @Assert\Regex(pattern="/([0-9]{4})/", message="Please use the YYYY format")
* @Type("string")
* Example "2014"
*/
protected $year;
However, whenever I create a new document and persist it to MongoDB, Doctrine doesn't enforce any Assert definitions at all... it allows just about any value to be saved for this field.
Any ideas?
Thanks @Maerlyn. Yes, apparently, I need to do proper validation before I persist the document eg
$validator = $this->get('validator');
$violations = $validator->validate($myObj);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.