How to apply UniqueEntity authentication to a superclass

When defining an abstract superclass with multiple implementations, I cannot get a UniqueEntity check.

For example, when creating AbstractUser having an email field and FacebookUser / TwitterUser, UniqueEntity only checks the subclass. Not a parent.

Any ideas on how to apply Unique validation at the top level?

EDIT: I am using the table inheritance joined with the discriminator column. See doctrine documentation.

+4
source share
2 answers

You may need to write your own validation constraint to verify uniqueness in this case.

It is logically incomprehensible how the UniqueEntity constraint is applied in this case. Are all extending classes checked for property uniqueness or only for the current class?

Because the UniqueEntity constraint looks for the uniqueness of a property in the table, the second option is not covered by the default behavior. Therefore, you cannot use the restriction for an extensible class with a single table overlay at this time.


Regarding the comments:

FOSUserBundle does not include the UniqueEntity constraint in config / validaton.xml .

... but it can be found for orm, mongodb, couchdb and propel, i.e. in config / orm / orm.xml .

FOSUserBundle uses @MappedSuperClass instead of merged table inheritance.

+1
source

You can define the entityClass parameter in the superclass constraint configuration as follows:

 /** * @UniqueEntity(fields={"email"}, entityClass=User::class) */ 
0
source

Source: https://habr.com/ru/post/1392532/


All Articles