-
-
Notifications
You must be signed in to change notification settings - Fork 11
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
Mapping: Appending to list, Adding to dictionary #143
Comments
Mapping rules are used to build up a dictionary of keywords that are applied to a new resource instance, this doesn't allow for fields to be appended to, however, a mapping rule can accept multiple inputs allowing for your mapping to be defined as: class AirTableProductToShopifyProduct(odin.Mapping):
from_resource = AirTableProduct
to_resource = ShopifyProduct
@odin.map_list_field(from_field=('wholesale_price', 'sample_price')
def metafields(self, wholesale_price, sample_price):
return [wholesale_price, sample_price] |
See the examples in the mapping docs. |
Thank you, ideally for me there would be a way to have independent mappers to append to the list. I have 20 input fields, that need to be appended to this list. To make the code more testable and maintainable, it would be useful to have a way of defining independent mappers, that append to the list. I will close this for now, but please consider this feature. Thanks! |
I've been thinking about how that would be achieved effectively, as this is a bit of a special case I'm loath to add more complexity and change the behaviour of the internals of mappers to maintain compatibility with existing usage. One possible solution would be a "combining rule" that can append the results of several rules (internally a field mapping is defined as the action on a mapping rule) before returning the final result. This would allow for more flexibility without needing to modify the internals of mappers. I'm going to re-open this issue as a feature request. |
I'm trying to map between two resources
Specifically, I want to find out how to append to a field on the
to_resource
I can't work out how to do this. I've tried to access theto_object.metafields
on self to keep appending, but I don't see it avaiable. Any tips?The text was updated successfully, but these errors were encountered: