-
Notifications
You must be signed in to change notification settings - Fork 45
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
How to specify which property to extract when using dictionaryFromObject() method? #18
Comments
Try using this:
Having upsert policy set to UpsertModePurgeExistingObject deletes the existing (if it finds an existing) one and creates a brand new one, which means it triggers all your cascade delete rules Let me know if this does what you are looking for |
Thanks for the quick reply. This is not my issue I think. I'm actually setting a unique key for my class with the mode UpsertModeUpdateExistingObject. It works great. But when I want to generate a dictionary from my object model, the dictionary returned has all the objects properties plus the ones related to any NSManagedObject class. For example, for the following class:
I'll get a dictionary with maybe 10 key/value pairs more than the number of the object properties: "name": .... I'd like to obtain a dictionary that contains only the properties of my object. Hope it's more clear. |
Got it, I used the runtime API for all object to dictionary conversion. |
Cool, thanks a lot! |
This would be really helpful for regular NSObjects as well; I'm currently running into this issue with my own NSObject models. Also, sometimes I only want to send changed properties to a PATCH request. So perhaps it would be better to be able to submit a whitelist of properties you want published, maybe via a new |
@hopiaw @poetmountain I'm adding this feature today.
|
Example: mappingProvider.excludeMappingForClass(NSManagedObjects.self, withKeys: ["faultingState", "deleted"]) |
@aryaxt If I'm understanding this correctly, this method would apply a global whitelist per-model? I think this probably addresses hoplaw's use-case, but in a case where you're sending a partial model via PATCH, and those model properties might be different every time (e.g. Message model where user can edit a 'title' or a 'body' property individually), a class-level whitelist wouldn't work. But perhaps that sort of dynamic model filtering isn't worth putting into the lib. |
Yeah, feels like it would be easier to manually generate a dictionary, versus using the library with a whitelist properties array. The feature I added is a static mapping feature |
Hi,
When using the following method:
and object inherit NSManagedObject, the dictionary returned has a lot of NSManagedObject properties that I'd like to remove (like inserted, deleted, hasChanges, faultingState etc). Is there is an easy way to do that?
Thanks
The text was updated successfully, but these errors were encountered: