Mapping to child classes
mschop opened this issue · 3 comments
Hi,
I'm trying to use automapper-plus in the latest version (1.2.1) with Entity classes used in doctrine ORM. Doctrine ORM creates Proxy-Classes that inherit from the Entity class for adding additional stuff (e.g. loading assosiations).
My problem is, that automapper-plus seems not to work in this case. When trying to map from the proxy class to the target object, it says:
No mapping registered for converting an instance of class Proxies\__CG__\App\Entity\UserAddress into one of App\FormModel\UserAddressFormModel
I think this should be working, because every child class is an instance of the base class and should provide the same interface (Liscov Substitution Principle). The mapping should therefore apply to all sub classes.
Best Regards
mschop
Ahhh sorry. Didn't see the other issue on this topic. #9 . This issue can therefore be closed.
You do have a point about the substitution. While #9 addresses the Doctrine issue, I'll keep this one open for checking if substitution works correctly.
@mark-gerarts #9 seems to be just this substitution problem. I have fixed my problem in the app by doing this:
$config->registerMapping(UserAddressFormModel::class, UserAddress::class)->reverseMap();
// This is needed, because of this issue: https://github.com/mark-gerarts/automapper-plus/issues/9
// Therefore this could be deleted in future
$config->registerMapping(UserAddressFormModel::class, "Proxies\__CG__\App\Entity\UserAddress")->reverseMap();
Maybe not the best solution, but work for me in the first step