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条回答 默认 最新

报告相同问题?

悬赏问题

  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型
  • ¥50 buildozer打包kivy app失败
  • ¥30 在vs2022里运行python代码
  • ¥15 不同尺寸货物如何寻找合适的包装箱型谱
  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作