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

报告相同问题?