-
Notifications
You must be signed in to change notification settings - Fork 13
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
Adding a transformer to an array of objects #111
Comments
It should not be a problem normally, we may need more context or a simple reproducer so we can see what's the problem here |
I'll try to provide a little more context: So here's a snippet of the entity which I'm trying to map to:
Without adding a custom transformer it uses No custom transformer on colours property Custom transformer on colours property I've tried both these approaches but same result:
Bottom line I'm trying to hydrate the entities using the transformer, so please let me know if there's a way without using transformers! |
Does the |
Yes you could use a provider see https://automapper.jolicode.com/dev/mapping/provider/ |
Yeah, you can see on the 2nd screenshot it correctly attaches to Not really sure this is the "problem" but I've been trying to understand why the code is not getting attached and found that it might be related to this. |
Not exactly but something close to this: this may be because there is a transformer on a collection but the hydrate part can only be done with add / remove method. I will try to look at that, can you add a 'setColours' on the target to see if it works ? (or make the property public) |
Didn't seem to make a difference |
No luck with Providers, are you able to share a working example? |
Yeah, for the record, provider was badly injected in the bundle (should be fixed in next version). For adder and remove i made #116 which should resolve your first issue. For the record, it will transform the array entirely, transformer will not be applied to the item (so it need to handle an array as an input and return an array). Then it will correctly used the adder method I think it's better than the item, as it will allow, in your case, to fetch a collection instead of doing a sql query for each item, also this is consistent with other way to write the values. |
Hello,
I'm trying to transform an array of objects (DTOs) into an array(entities), Is that something that the library is capable of handling?
Here's a snippet of the code:
When looking at the automapper tab in the profiler although it attaches AutoMapper\Transformer\PropertyTransformer\PropertyTransformer there's no code inside.
I've the same setup for simple properties, so I know the problem is probably not the transformer.
Let me know if you need more context.
Thank you!
The text was updated successfully, but these errors were encountered: