fetchRequestBlocks for nested objects

15 views
Skip to first unread message

Dan Morrow

unread,
Feb 3, 2015, 11:05:24 AM2/3/15
to res...@googlegroups.com
I make a call to a service, and get a result back like this:

{
   main_object
: {
      name
: "Main 1",
      id
: 12345,
      color
: "red",
      items
: [
         
{
            itemName
: "abcd",
            itemId
: "2",
         
},
         
{
            itemName
: "egde",
            itemId
: "3",
         
},

         
{
            itemName
: "rororo",
            itemId
: "4",
         
}
     
]

   
}
}


The service returns "main_object" (which is a managed-object) and it's list of items, which are also managed objects.

I've called "addFetchRequestBlock" for other services that I call... ones that return solely a list of items. But this one returns an object that contains a list of items. I need to persist both the object and it's list.

When I want to fetch the local items, I can just created a fetch request where "parentItem.id == 12345" in this case. And that's all good. My concern is about what happens to the orphaned objects. Not sure how to write a fetchRequestBlock that will handle nested managed objects.

Is this possible with this mechanism, or do I need to do something completely different?


Dan Morrow

unread,
Feb 3, 2015, 12:05:26 PM2/3/15
to res...@googlegroups.com
Just found the answer on github

Basically, I need to create two fetch-request blocks. One to get "main_object" and the other to get the "items". Both of these blocks will check for the same URL pattern. So, once the orphaned-object deletion happens, it will look at the list of objects from both of these fetchRequestBlocks.
Reply all
Reply to author
Forward
0 new messages