I've having an issue where CoreData is unable to fulfill a fault on an object. I assume it's because the object has been deleted and now CoreData is trying to access a property in some context and can't fault it in. To resolve this I attempted to call setRelationshipKeyPathsForPrefetching
and pass it the relationships that I want to have prefetched.
Example, I have an Entity A, and it has a to-many relationship to Entity B, but at some point while I'm accessing properties on Entity B, Entity B is deleted in another context and now a fault can't be fulfilled.
[request setRelationshipKeyPathsForPrefetching:[NSArray arrayWithObjects:@"listOfBs", nil]];
I thought that if I did this, it would prefetch Entity B so that I can call its properties safely but this doesn't seem to be the case.
EDIT: I can't seem to find any info about this but it must be a fairly common problem. If some context has a managed object that is deleted in another context, it should have some way to safely figure out that the object no longer exists rather than just crashing
EDIT 2: I don't think CoreData is properly acknowledging my prefetch request. If I call setRelationshipKeyPathsForPrefetching than the objects that are returned should be faulted in yet even in the case where I don't have an error, I can simply print out the object that get returned and see that they are faulted. Does CoreData not prefetch objects in to-many relationships?
EDIT 3: Ok so perhaps the relationships themselves are prefetched but the properties on the prefetched items are not faulted in. So if I have Entity A and I want to prefetch all of the B's associated with A, I use setRelationshipKeyPathsForPrefetching but all of the properties of the B's are not faulted in.