Skip to content

UniqueEntity constraint usage inside a collection #10942

Closed
@fabienlem

Description

@fabienlem

Hello,

The UniqueEntity constraint is useful to check whether a similar entity already exists in the database.

But suppose this constraint is used inside a collection (via embedded forms for instance). In this case, the constraint is not able to detect duplicates within the non-persisted entities.

See this issue in the Symfony repository.

In the current documentation, we can read that the constraint Validates that a particular field (or fields) in a Doctrine entity is (are) unique. I think it can be confusing.

What do you think of adding a warning message regarding this use case? (imho it's something different that the existing race-conditions warning message).

Something like: "When used inside a collection, the UniqueConstraint cannot deal with duplicates whithin the non already persited entities. You have to implement your own validator in order to handle this situation.".

Thank you for reading!

Fabien

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoctrineValidatorhasPRA Pull Request has already been submitted for this issue.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions