Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[WCM][DoctrineBridge] Fix UniqueEntity interaction with inheritance#16981
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
[WCM][DoctrineBridge] Fix UniqueEntity interaction with inheritance#16981
Uh oh!
There was an error while loading.Please reload this page.
Conversation
### DoctrineBridge and Validator | ||
* If you were using the `StaticMethodLoader` to create `UniqueEntity` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Isn't is possible to iterate over$metadata->getConstraints()
in theStaticMethodLoader
in order to avoid this ?
foreach ($metadata->getConstraints()as$constraint) {if ($constraintinstanceof TargetAwareConstraintInterface) {$constraint->target =$metadata->getClassName(); }}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
It could be, however the current behavior ofStaticMethodLoader
is to do the bare minimum and to let the implementation of the loader method do all the heavy lifting work.
That's why I didn't implement the support for TA constraints in there. But, yeah, it could be done, I guess... I will add a note in the other PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
PS: The use case would still be possible (and the deprecation still required) for custom constraint loaders, just thought about that...
Won't it be a BC break as this behavior is the |
a610e22
toe0ff5d5
CompareWell, the way I see it, it would be a BC break if the previously correct behavior was changed. But since the |
e0ff5d5
to2d9946c
Compare@lemoinem : I've thought about edges cases with this proposal: What if the |
$target = $constraint->target; | ||
/* @var $target string */ | ||
if (!$constraint->target) { | ||
@trigger_error('Not providing a target for a UniqueEntity constraint is deprecated since version 3.1 and will be removed in 3.0.', E_USER_DEPRECATED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
- @trigger_error('Not providing a target for a UniqueEntity constraint is deprecated since version 3.1 and will be removed in 3.0.', E_USER_DEPRECATED);+ @trigger_error('Not providing a target for a UniqueEntity constraint is deprecated since version 3.1 and will be removed in 4.0.', E_USER_DEPRECATED);
(4.0, not 3.0)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Good Catch. Thank you!
2d9946c
to36f10c9
CompareIndeed, that's a very good point... I didn't consider it because having a However, that would definitely be a BC Break... I'm thinking the best way would be to grab the highest parent of the current entity, among the descendants of the target that IS an Entity and use ITS Repository. By this, I mean, given these classes:
calling the validator on an instance of Using the Repository of Trying to compute the exact match (i.e. trying to lookup in the Repositories of |
I don't see what you mean. The file I linked above is from the master branch and so is FOSUser 2. :/ Your new suggestion seems good to me however. |
I was referring toFriendsOfSymfony/FOSUserBundle@047b0e6 which deleted the Entity classes. Since this commit, in However, having a Thank you for the feedback! |
After testing (https://github.com/lemoinem/symfony-standard/tree/test/doctrine/mapped-superclass-repository, This doesn't change much to the implementation I intended to put in place. |
36f10c9
to7937237
Compare7937237
to54fc801
Compare35d86d9
to2bb4810
CompareOK, I finally had time to write a relevant test case for the repository search. PS: I also took the chance to rebase both PRs. The PHP 5.6 Travis build currently fails because of FrameworkBundle errors which aren't related to this PR. |
* | ||
* @return \Doctrine\Common\Persistence\Mapping\ClassMetadata | ||
*/ | ||
private function findHighestEntityMetada(ClassMetadataFactory $metadataFactory, $target, $entityClass) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
typo
- findHighestEntityMetada+ findHighestEntityMetadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Yup, indeed!
Thanks!
Fixessymfony#16969Fixessymfony#4087Fixessymfony#12573Incompatible withsymfony#15002Incompatible withsymfony#12977
2bb4810
to3868657
Compare
StaticMethodLoader
or a custom Constraint Loader is used to loadUniqueEntity
constraintsThis is the second half of#16969 with the actual fix.
This version of the code is ready for code review. However, since I'm dependent on#16978, I'm leaving the PR as a WIP until the dependence is merged and I rebase the current one on master.
Since I introduce deprecations, I updated
UPGRADE-4.0.md
.Manage the case where@UniqueEntity
is attached to a non-Entity class