In my Core Data model I have two entities: "Photo" and "Tag". The relationship between these is like : Photo << ------->> Tag.
When I insert a Photo into database and setup the relationship, then I want to fetch an NSArray of photos using an entity "Tag". The code is:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(ANY tags == %@)", tag];
requestForPhoto.predicate = predicate;
NSSortDescriptor *sortD = [NSSortDescriptor sortDescriptorWithKey:@"title" ascending:YES];
requestForPhoto.sortDescriptors = [NSArray arrayWithObject:sortD];
NSArray *matches = [document.managedObjectContext executeFetchRequest:requestForPhoto error:nil];
the number of matches is 0; then I close the app, open it again and execute the upper code, the number turns normal, becoming 1.
I'm sure that I execute method saveToURL: forSaveOperation: to save the data.
I NSLog the content of database before and after re-open app, It works fine, the relationship has already established.
I have another Core Data model:
photo <<---------> location
when I fetch a photos, I use the NSString of location(not an entity) to do so.
the results is very regular.