I have a Core Data Entity called Trigger which has a many to one relationship with another Entity called ActiveTrigger. When I query Core Data for the Trigger object with [request setReturnsObjectsAsFaults:NO];
, the query result has an NSSet of ActiveTrigger Entities on each Trigger as trigger.activeTriggers. The ActiveTrigger objects however have a data fault which is not fired when I access any of the properties, but does fire when I access one of the relationships on the ActiveTrigger. Shouldn't the fault fire when accessing either a property or a relationship? After firing the fault with the relationship, the same property that returned (null) after not firing the fault returns is actual value.
NSFetchRequest * request = [NSFetchRequest fetchRequestWithEntityName:NSStringFromClass([Trigger class])];
[request setPredicate:[NSPredicate predicateWithFormat:@"identifier IN %@", triggerIds]];
[request setReturnsObjectsAsFaults:NO];
NSError * error = nil;
NSArray * results = [[NSManagedObjectContext sharedManagedObjectContext] executeFetchRequest:request error:&error];
for (Trigger * trigger in results) {
for (ActiveTrigger * activeTrigger in trigger.activeTriggers) {
NSLog(@"Here is the survey name as a property on the ActiveTrigger 1: %@", activeTrigger.surveyName);
NSLog(@"Here is the survey name via the relationship: %@", activeTrigger.survey.name);
NSLog(@"Here is the survey name as a property on the ActiveTrigger 2: %@", activeTrigger.surveyName);
}
}
//Here are the logs resulting from the code above
2016-03-01 13:48:28.809 AppName[31787:1480404] Here is the survey name as a property on the ActiveTrigger 1: (null)
2016-03-01 13:48:28.811 AppName[31787:1480404] Here is the survey name via the relationship: All Q
2016-03-01 13:48:28.811 AppName[31787:1480404] Here is the survey name as a property on the ActiveTrigger 2: All Q
A breakpoint after the first log confirms that the activeTrigger object still has a data fault after attempting to access the surveyName property