everyone. There is a similar question posted here, but the answer does not solve my error.
I'm trying to use Symfony 4.3 automatic validation on an entity, but it just doesn't work.
I've uncommented the two lines from validator.yaml
and I have enabled validation: {enable_annotations: true}
in framework.yaml
config file, and it still does not work.
Even if I add or remove @Assert annotations from the entity, the validation always returns a zero-length array.
This is my entity class:
namespace App\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
/**
* Company
*
* @ORM\Table(name="company")
* @ORM\Entity(repositoryClass="App\Repository\CompanyRepository")
*/
class Company
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @var string
*
* @ORM\Column(name="type", type="string", length=255, nullable=false)
* @Assert\NotNull
*/
public $type;
}
As you can see, the type attribute cannot be null, but the validation is not working as expected. This is it:
$company = new Company();
$validator = Validation::createValidator();
$errors = $validator->validate($company);
At this point, $errors is just an empty array.
Is there any extra configuration needed? Does anybody have a theory?