Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When does an object get a objectID that is not temporary?

I am inserting a new Folder entity into my model object context (MOC), that is a child of the master MOC. Before saving, [[newFolder objectID] isTemporaryId] returns YES. When I save first my MOC and then the master MOC and ask the [[newFolder objectID] isTemporaryId], it again says YES. I expected it to now be a persisted object, and indeed, if I interrogate the SQLite file, it contains the new folder. For the entire time of my running application, it will say YES. Not before I quit and restart, thus loading the object up from the store, does it say NO.

I always thought a NSManagedObject changed from a temporary object to a stored object with no longer a temporary objectID when it was saved. When does an object get a objectID that is not temporary?

Cheers

Nik

like image 983
niklassaers Avatar asked Feb 08 '12 11:02

niklassaers


1 Answers

Objects in child contexts aren't altered by changes in the parent context until the objects are refreshed. Perhaps refreshing the object after saving the parent context will do the trick.

If that doesn't work, there's always -[NSManagedObjectContext obtainPermanentIDsForObjects:error:].

like image 61
Becca Royal-Gordon Avatar answered Oct 04 '22 02:10

Becca Royal-Gordon