Note that there are some explanatory texts on larger screens.

plurals
  1. POCore data relationship lost after fetching more objects into the entities
    primarykey
    data
    text
    <p>I have a core data model that looks like this.</p> <p><img src="https://i.stack.imgur.com/lWA0E.png" alt="enter image description here"></p> <p>Inside a tableview I load up all my appointments. On a <code>UILabel</code> inside my <code>custom cell</code> I set the appointments location name as follows.</p> <pre><code>NSString *info = appointment.location.label_vrij; </code></pre> <p>At first everything works Oké, but when I load more appointments into my <code>database</code>. All the info strings goes <code>NULL</code>. After some debugging I noticed that also <code>appointment.location</code> returns <code>NULL</code>.</p> <p>This is how my NSFetchRequest looks like</p> <pre><code>RKManagedObjectStore *store = [[SanMaxDataModel sharedDataModel] objectStore]; NSManagedObjectContext *context = store.mainQueueManagedObjectContext; NSFetchRequest *fetchRequest = [NSFetchRequest fetchRequestWithEntityName:@"Appointment"]; NSString *relationshipKeyPath = @"location"; // Set this to the name of the relationship on "A" that points to the "B" objects; NSArray *keyPaths = [NSArray arrayWithObject:relationshipKeyPath]; [fetchRequest setRelationshipKeyPathsForPrefetching:keyPaths]; NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:@"dateStart" ascending:YES]; fetchRequest.sortDescriptors = @[descriptor]; NSPredicate *predicate = [NSPredicate predicateWithFormat: @"tijd_dag = %@",strDate]; [fetchRequest setPredicate:predicate]; NSArray *matches = [context executeFetchRequest:fetchRequest error:nil]; appointments = [matches mutableCopy]; </code></pre> <p>So I think my relationship is just messed up ?</p> <p><strong>EDIT</strong></p> <p>I'm using Restkit for mapping my appointments into my core database. From the comments below I decided to turn off the option flag off the location attribute inside the Appointment entity. Because an appointment should always have a location. </p> <p>Now when I load up the first day. Everything works oké. But when i try to load up the next day , I get the error: <code>The operation couldn\U2019t be completed. (Cocoa error 1570.)</code> Now when I take a look at the detailed Error</p> <pre><code>DetailedError: { NSLocalizedDescription = "The operation couldn\U2019t be completed. (Cocoa error 1570.)"; NSValidationErrorKey = location; NSValidationErrorObject = "&lt;Appointment: 0x864e2f0&gt; (entity: Appointment; id: 0x9272c70 &lt;x-coredata://9692683D-3077-4362-9253-652AC5B36444/Appointment/p9&gt; ; data: {\n autouur = 1;\n breekuur = 0;\n data1 = \"\";\n data2 = \"\";\n data3 = \"\";\n data4 = \"\";\n data5 = \"\";\n data6 = \"\";\n data7 = \"\";\n data8 = \"\";\n data9 = \"\";\n dateStart = \"2013-10-23 09:00:00 +0000\";\n dateStop = \"2013-10-23 09:30:00 +0000\";\n duration = 30;\n email = \"\";\n entryID = 774294984959;\n info = \"\";\n \"is_blocked\" = 0;\n \"is_except\" = 0;\n \"is_free\" = 1;\n \"is_moved\" = 0;\n \"is_vert\" = 0;\n locatieID = 773150;\n location = nil;\n multiID = nil;\n serverEntryID = 774294984959;\n serverLocatieID = 773150;\n sms = \"\";\n \"tijd_dag\" = 20131023;\n \"tijd_uur\" = 900;\n})"; } </code></pre> <p>This is how I load up the JSON in core data</p> <pre><code>-(void)getAppointmentsForDate:(NSString *)date forUserID:(NSString *)userID{ API *api = [API new]; RKManagedObjectStore *store = [[SanMaxDataModel sharedDataModel] objectStore]; NSLog(@"store is %@",store); NSManagedObjectContext *context = store.mainQueueManagedObjectContext; RKObjectManager *objectManager = [api mapAppointments]; NSString *urlString = [NSString stringWithFormat:@"/doctor/1.0/json/nl/appointments/get-by-date/apikey/%@?uid=%@&amp;date=%@",APIKey,userID,date]; // NSString *urlString = [NSString stringWithFormat:@"/doctor/1.0/json/nl/appointments/get-by-date/apikey/%@?uid=77382&amp;date=%@",APIKey,date]; NSURLRequest *request = [objectManager requestWithObject:nil method:RKRequestMethodGET path:urlString parameters:nil]; RKManagedObjectRequestOperation *operation = [objectManager managedObjectRequestOperationWithRequest:request managedObjectContext:context success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) { NSLog(@"TILL HERE IN METHOD"); NSError *error = nil; [[NSNotificationCenter defaultCenter] postNotificationName:@"appointmentsLoaded" object:self]; [[SanMaxDataModel sharedDataModel] saveToPersistentStoreAsync:&amp;error]; } failure:^(RKObjectRequestOperation *operation, NSError *error) { UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:[error localizedDescription] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; [alert show]; NSLog(@"Hit error: %@", error); }]; [objectManager enqueueObjectRequestOperation:operation]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload