When loading data into Core Data, my child objects aren’t getting the parent ID set. This is all generated as I walk through an xml document using TBXML. (code heavily paraphrased for brevity)
a = NSEntityDescription insertNewObjectForEntityForName:@"A"
set various a attributes
if a.Type isEqualToString:@"TypeA"
b_set = NSMutableSet new
for each child element of a
b = NSEntityDescription insertNewObjectForEntityForName:@"B"
set various b attributes
b.a = a
b_set addObject:b
next
a.bs = b_set
end
blah blah blah
When all is said and done, all the a’s and b’s, and all their atttributes are correctly persisted to SQLite, except that all the b’s have null for their a (the parent) attribute.
Do I have to rework this to write the a before creating the b’s so they have a real objectID to reference?
Reverse relationships are updated as part of
-processPendingChanges. That will get called as part of-save:. If you need to, you can call it directly. CoreData will not update the reverse relationships immediately since it’s costly.