1

Using NSFetchRequest, is it possible to avoid fetching a NSManagedObject that has been or will be deleted?

I know it's possible to check -isDeleted or if -managedObjectContext returns nil, but is there a way to do this in the database layer?

hwaxxer
  • 3,363
  • 1
  • 22
  • 39

1 Answers1

0

Technically, if the object is truly deleted it will not show up at the database layer. What are the symptoms of the problem presenting as?

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43
  • Maybe the phrase "database layer" was misleading. I want to know if it's possible to avoid fetching objects that will be removed from the store with the next save operation. – hwaxxer Feb 26 '12 at 12:30
  • Still not sure why you might want to do that. If your application is multithreaded, it's possible that any object might get deleted (and thus turn into a fault). If you are using one `NSManagedObjectContext` then as Costique says, saving it first will at least ensure that the pending deletes get pushed down to the `NSPersistentObjectStoreCoordinator`.Pending deletes would only be known to the individual `NSManagedObjectContext` anyway, not to peer ones hanging off the same persistent store. Can you elaborate on exactly what problem is causing you to want the fetch to work this way? – Scott Corscadden Feb 27 '12 at 13:21
  • I'm syncing with a web service, inserting and deleting objects at arbitrary times. The UI is observing changes to the context and creates a fetch request whenever a particular change occurs. However, this request is also returning the objects to be deleted with the next save and I'd rather filter them out in the request than after fetching. – hwaxxer Feb 27 '12 at 13:50