I am trying to validate an attribute at a field level by the @Assert\Expression (http://symfony.com/doc/2.4/reference/constraints/Expression.html).
It works at a class level with this code:
/**
* Foo
*
* @ORM\Table(name="foo")
* @ORM\HasLifecycleCallbacks()
* @UniqueEntity("slug")
* @Assert\Expression(
* "this.getPriceFor2PaxStandard() != null or (this.getPriceFor2PaxStandard() == null and !this.isPriceForAccLevelRequired('standard'))",
* message="The price for 2 pax standard is required",
* groups={"agency_tripEdit_finalsave"}
* )
*
*/
class Foo implements ISpellcheckerLocaleProvider, ProcessStatusAware, DataTransformer
{
but if I use the same code (which should be fine) at attribute level is not working:
/**
* @var decimal
*
* @ORM\Column(name="price_for_2_pax_standard", type="decimal", precision=16, scale=4, nullable=true)
* @Assert\Expression(
* "this.getPriceFor2PaxStandard() != null or (this.getPriceFor2PaxStandard() == null and !this.isPriceForAccLevelRequired('standard'))",
* message="The price for 2 pax standard is required",
* groups={"agency_tripEdit_finalsave"}
* )
*/
private $priceFor2PaxStandard;
In addition, does not work either if I use value instead of this.getPriceFor2PaxStandard() when using the asseriont as a attribute level.
Any hint would be appreciated :-)