Fix interfaces mapping in Doctrine for admin user and shop user#10450
Conversation
bbc1f07 to
285fae9
Compare
|
|
|
Thank you so much! 🚀 |
| return; | ||
| } | ||
|
|
||
| $resolveTargetEntityListener->addMethodCall( |
There was a problem hiding this comment.
Are you sure this does not break the AdminUser entity? As far as I see this will replace its target-entity with a ShopUser as well.
There was a problem hiding this comment.
Before this PR, Sylius\Component\User\Model\UserInterface targets ShopUser entity (cause it's the last one to define Sylius\Component\User\Model\UserInterface as its interface). This will preserve backwards compatibility (could be removed in 2.0).
There was a problem hiding this comment.
Currently at lunch, but I think I remember the AdminUser mapping using the same interface for its user-relation.
There was a problem hiding this comment.
That's correct, but shop user comes next and overwrites it :)
There was a problem hiding this comment.
Isn't resolveTargetEntity replacing all occurrences of OriginalTargetEntity with NewTargetEntity and thus both AdminUser and ShopUser use the NewTargetEntity (ShopUserInterface) as its target-entity?
There was a problem hiding this comment.
It works like this (simplified 🎉):
$interfaces = [];
$interfaces[UserInterface::class] = AdminUser::class;
$interfaces[UserInterface::class] = ShopUser::class;
var_dump(str_replace(
array_keys($interfaces),
array_values($interfaces),
UserInterface::class
));
// string(8) "ShopUser"There can be only one target entity for a given interface.
There was a problem hiding this comment.
Wait - I think thats on me.
I got ResourceBundle config and mappings mixed up.
The AdminUser and ShopUser had the same interface configured for its resource, but the ShopUser is the only one being used with UserInterface in a relation (Customer in this case).
The AdminUser::class has no target-entity for nothing, so my worries fizzle.
The ShopUser::class is (only) being used by the Customer as an inverse relation with target-entity UserInterface (which gets corrected anyways) and thus re-mapping UserInterface to ShopUserInterface (or the currently configured resource-class) in the whole application is totally fine.
My bad, thanks for your time though ❤️
Both the first and the second commit should pass before merging this PR. This assures as the changes as backwards compatible (second change resigns from BC layer).