Search code examples
core-datarestkitnsfetchrequestrestkit-0.20

NSFetchRequest when a call returns multiple collections


I am trying to set up RestKit to delete orphaned objects that don't exist on the server but still exist in the local cache, using NSFetchRequests as described in the documentation for RKManagedObjectRequestOperation.

If I have a call that returns multiple collections of different object types, each of which are mapped using keys, is RestKit smart enough to deal with this? Or will it only work on calls that return objects of a single type? For example:

URL: /users?accessToken=someToken

Response:

{
    users: [],
    collection1: [],
    collection2: [],
    collection3: []
}

The type of object stored in each collection is a different Entity in my data model. How can I write an NSFetchRequest that will allow me to delete objects from the local cache that are no longer in collection1, collection2, or collection3?


Solution

  • It's as smart as you make it, but, as you can see from the docs / block signature, you need to have some information in the URL (or in the previously mapped contents in the data store) which allows you to decide what to do.

    If all of your information is in the JSON response body them using a fetch request block may not work well for you and you may need to execute your own fetch and deletion based instead on the mapping result (which would run after the context was saved instead of before).