使用多个属性而不是 validation.yml symfony2 中的一个的唯一实体约束

unique entity constraint using SEVERAL properties instead of one in validation.yml symfony2

使用 Symfony2.3.​​4、Doctrine2 和 PHP5.6.3.

这是我的 validation.yml 文件:

Project\NameBundle\Entity\EntityName:
    constraints:
        - Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity:
            fields: f1
            message: "There is already an entity with the same f1"
            fields: f2
            message: "There is already an entity with the same f2"

这只是一个直观的帮助,可以帮助您了解我的需要。这不符合我的意愿。这个:

提交表格时:
- 当前行为:

if(f2 is not unique)
   error;
else
   submits;

预期行为:

if(f1 === X.f1 AND f2 === X.f2)  //X is any of the entities already in the DB
   error;
else
   submits;

以防万一,我已经在 EntityName.php class 中使用 @UniqueEntity(fields={"f1", "f2"}, message="error") 注释完成了此操作,但我确实需要在 .yml.[=19= 中使用它]

支线任务:
现在,使用注释方法它只在 f1 旁边显示错误符号,有没有办法在所有相关字段旁边显示它?

文档 (http://symfony.com/doc/current/reference/constraints/UniqueEntity.html#fields) 说字段可以是数组:

fields: [f1, f2]

这里以 YML 格式为例进行说明:http://symfony.com/doc/current/components/yaml/yaml_format.html