有兩個物體:Product 和 ProductDetails:
class ProductDetail {
#[ORM\ManyToOne(targetEntity: Product::class, inversedBy: 'productDetail')]
#[ORM\JoinColumn(nullable: false)]
private $productItem;
#[ORM\Column(type: 'date', nullable: true)]
#[Assert\GreaterThan('today')]
#[Assert\Expression(
expression: 'this.getProductItem()->getStatus() in ['not done'] or value',
message: 'The planification date cannot be null for this status!',
)]
private $finishedDate;
class Product {
#[ORM\Column(type: 'string', length: 255)]
private $status;
基本上我想為finishedDate狀態為“未完成”時不允許為空創建一個約束。但它并沒有絕對沒有任何作用,我很好奇我是否遺漏了任何東西。即使我放在value那里并且日期為空,也不會觸發訊息。
uj5u.com熱心網友回復:
根據此鏈接:https ://symfony.com/doc/current/components/expression_language/syntax.html 。
你能試試:
this.getProductItem().getStatus()
您可以在您的情況下使用自定義約束,它更靈活: https ://symfony.com/doc/current/validation/custom_constraint.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/517426.html
標籤:交响乐表达
上一篇:找不到相關命令
