This is quite funny. In my application I create thousands of entry in the database (in another thread, I'm using MagicalRecord). Everything seems working fine (from a background/foreground/context point of view).
When, in the main thread, I try to fetch the "just inserted" data, I discovered the following behaviour:
- (NSArray *) familiesInCompany:(Company *) company {
NSPredicate *predicate1 = [NSPredicate predicateWithFormat:@"company == %@", company];
NSPredicate *predicate2 = [NSPredicate predicateWithFormat:@"company.name == %@", company.name];
NSArray *first = [Family MR_findAllSortedBy:@"name" ascending:YES withPredicate:predicate1];
NSArray *second = [Family MR_findAllSortedBy:@"name" ascending:YES withPredicate:predicate2];
NSArray *third = [Family MR_findByAttribute:@"company" withValue:company andOrderBy:@"name" ascending:YES];
return second;
}
Now what I get is:
- first: is an empty array
- second: contains all the
Family
objects, as expected - third: is an empty array.
By debugging the SQL statement I get the following:
The "first" statement:
CoreData: annotation: total fetch execution time: 0.0000s for 0 rows.
The "second" statement":
CoreData: sql: SELECT 0, t0.Z_PK, t0.Z_OPT, t0.ZNAME, t0.ZCOMPANY FROM ZFAMILY t0 JOIN ZCOMPANY t1 ON t0.ZCOMPANY = t1.Z_PK WHERE t1.ZNAME = ? ORDER BY t0.ZNAME
CoreData: annotation: sql connection fetch time: 0.0005s
CoreData: annotation: total fetch execution time: 0.0007s for 2 rows.
The "third" statement:
CoreData: annotation: total fetch execution time: 0.0000s for 0 rows.
The hilarious thing is that I close the application (I mean really manually terminate it) and and I open it back, all the three "fetching" statements work.
Why the first and the third fetch statements seem to never being executed? How to dig into the problem?