-
Notifications
You must be signed in to change notification settings - Fork 17
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Missing target data in Custom Transformer #172
Comments
Same issue here. My case:I map the DTO, containing some references as integer IDs to the Doctrine Entity, containing related entities of the different types - so i want to create a correspondent Entity based on its ID for every DTO/Entity property pair. Now, i have no possibility to determine the target Entity class with this concrete ID. My proposal:Give the |
I think you can use TransformerFactory for that, they get all needed metadata. For example something like that class GenericTransformerFactory
{
public function getTransformer(TypesMatching $types, SourcePropertyMetadata $source, TargetPropertyMetadata $target, MapperMetadata $mapperMetadata): ?TransformerInterface
{
$targetType = $types->getTargetUniqueType($types->getSourceUniqueType());
return new GenericTransformer($targetType->getClassName());
}
} But |
@MrMeshok Thank you for your advice! |
It would be great to have access to the target object's data and the specific property being transformed in the transform method of a custom transformer. This would greatly help in creating more generic data transformation rules.
If I have a data field that contains IDs instead of specific objects, and I want to create a generic transformer to translate IDs into objects, I currently have to create a separate transformer for each transformation. The only difference between these transformers is the className, which seems unnecessary to me. If I had access to the target object's data, I could determine this directly within it (similarly to the support method).
The text was updated successfully, but these errors were encountered: