2

Is there a way to configure UniqueEntity to treat foo and Foo as duplicates?

Use case: I have @UniqueEntity("email") on my user entity, since I'm using the email address as username. According to https://stackoverflow.com/a/9808332/1668200 the local part of an email address is case-sensitive in theory, but case-insensitive in practice.

I could certainly convert it to lowercase in setEmail() (as suggested at https://stackoverflow.com/a/31663365/1668200). Drawbacks:

  • Might confuse users (since their email address gets "modified")
  • As a comment of the above answer says:

    That's not a good idea, since there is a small chance it will not get delivered.

So I'd rather reject the user Foo@example.com's registration (if foo@example.com is already present), than convert all users' addresses to lowercase.

Thomas Landauer
  • 7,857
  • 10
  • 47
  • 99

1 Answers1

3

Based on this UniqueEntity:

repositoryMethod type: string default: findBy()

The name of the repository method to use for making the query to determine the uniqueness. If it's left blank, the findBy() method will be used. This method should return a countable result.

You could create a function in the repository to find if that email exists applying UPPER() in the sql.

AythaNzt
  • 1,057
  • 6
  • 14