donglian1953 2016-04-30 14:58
浏览 56
已采纳

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

Using Symfony2.3.4, Doctrine2 and PHP5.6.3.

This is my validation.yml file:

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"

This is just a visual aid to help you understand what I need. This does not work how I want to. This:

When submitting the form:
- Current behavior:

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

Expected behavior:

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

Just in case, I have already accomplished this in my EntityName.php class with @UniqueEntity(fields={"f1", "f2"}, message="error") annotation, but I really need it in .yml.

Side quest:
Right now, with the annotation approach it is showing the error sign next to only f1, is there a way to show it next to all involved fields?

  • 写回答

1条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥20 webapi项目的XUnitTest单元测试怎么注入token和自写拦截器(filter)(语言-c#)
      • ¥15 exe和xml必须在一个文件夹才能打开exe文件
      • ¥15 房号如何排序,sql或算法
      • ¥15 macOS使用IDEA 2022.2.4打包JDK6项目报错
      • ¥20 OpenCV-Python简单轮廓寻找
      • ¥20 使用matlab进行含参数的最优化求解及数值模拟
      • ¥20 MATLAB找出一维变量中的局部极大值和局部极小值,并进行运算
      • ¥15 有Chang求三维杆单元几何非线性分析matlab代码
      • ¥50 使用unity easyar录屏功能。录屏视频整体色调很暗
      • ¥50 pyinstaller 打包问题