Hi, after I insert a ManagedObject into a context I'd like to fetch it later but before saving the context (I'd save after all objects are inserted). It appears that querying the context later with a fetch concerning those objects returns nothing if the context wasn't previously saved. Is there a way to save only in the end ?(I guess i can save my objects in an array or dictionary and query that but i thought coredata would do this for me)
+2
A:
Try this:
[myFetchRequest setIncludesPendingChanges:YES];
From the documentation:
Sets if, when the fetch is executed, it matches against currently unsaved changes in the managed object context.
Mike Weller
2010-07-13 08:55:03
I saw that before but it seems not to work, the fetch returns a 0 element array but the context shows 20 objects in it (I log it with [[moc insertedObjects] count]), while if i saved before the moc contains only 1 inserted object (I inserted it before fetching, but nevermind) and the array of fetched objects has length of 1 (which is correct). Maybe it is because my context is bounded to a persistent store, shall I link it to an in-memory store?
rano
2010-07-13 09:25:20
This should work regardless of where the store is. If you have multiple context, remember that you can fetch only the unsaved objects inside each individual context until each context has saved to the store.
TechZen
2010-07-13 14:29:41