I have an entity with the field $companies. This field has to store an array of Company objects. So I described assert this way:
@Assert\Type("Acme\MyBundle\Entity\Company")
But it's always invalid because from my form i receive array of Companies but this assert wants it be not array but just one Company.
So how to overcome this? I suppose that it has to be something like that:
@Assert\Array(Type("Acme\MyBundle\Entity\Company"))
Since the question is tagged for Symfony2.x, for the sake of completeness I have to point out that the new validation constraint All introduced since version 2.1 can do the whole job.
For each array or traversable objects (e.g. a Doctrine ArrayCollection
), you can do the following:
/**
* @Assert\All({
* @Assert\Type(type="Acme\MyBundle\Entity\EntityType")
* })
*/
protected $arrayOfEntities;
So, the Symfony2.1 users that are reading your question should prefer this elegant and clean solution.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With