I’m trying to see if I have a correct understanding of prefetching with Core Data. I’m executing a fetch request with a batchSize of 20 for a Message object, with has a to-one relationship with a MBDate property. I prefetch this property:
[fetchRequest setRelationshipKeyPathsForPrefetching:
[NSArray arrayWithObjects:@"date", nil]];
The prefetch command goes through, as shown by this output:
CoreData: annotation: Prefetching with key 'date'. Got 9 rows.
CoreData: annotation: total fetch execution time: 0.0094s for 20 rows
However, in just the first batch, if I do
if(message.date.isFault) NSLog(@"isFault");,
it always outputs isFault, even though I prefetched it! And if I try to access any of the properties of the MBDate object, a fault request fires:
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZDATE, t0.ZDATESTRING FROM ZMBDATE t0 WHERE t0.Z_PK = ?
CoreData: annotation: sql connection fetch time: 0.0008s
CoreData: annotation: total fetch execution time: 0.0014s for 1 rows.
CoreData: annotation: fault fulfilled from database for : 0x85d22b0 <x-coredata://736D04C4-7DB3-40B7-B208-79B5DFD68260/MBDate/p61>
Why is the prefetch not going through? Why are my objects still faults?
I know it’s hard to give any definite answers, but any tips or ideas would be great!
Can you try this same thing without setting batch size?
There is a curious note in NSFetchRequest Class Reference under fetchBatchSize:
It’s as if you set batchSize the objects returned will be faulted no matter what.