I have a core data setup that has 2 database entities. For the sake of names I'll call them Primary and Secondary. Secondary only belong to one Primary (relationship is setup). In my main view that lists the Primary objects in a table I retrieved them and put them in an PriObject Class which stores it's properties (including the managed object ID). The PriObject is then added to a mutable array (priArray), which is then used to fill the table with the data. All works ok so far. When I then click on the row I can log the PriObject.moID.
I can't figure out how to lookup that object in the database so I can then add Secondary objects to it. I can't do it by name because some Primary might have the same name.
I need to work out how to get an object back from either the URI or the ID. I have the ID so I can generate the URI if I need to.
Can't get my head around it at all and any examples I have found while looking don't cover what I need. What options are there?
EDIT: I am currently getting all my objects with the following.
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate managedObjectContext];
NSEntityDescription *entityDesc = [NSEntityDescription entityForName:@"Primary"
inManagedObjectContext:context];
NSFetchRequest *request = [[NSFetchRequest alloc] init];
[request setEntity:entityDesc];
NSError *error;
NSArray *objects = [context executeFetchRequest:request
error:&error];
if ([objects count] == 0) {
NSLog(@"Nothing found");
} else {
NSLog(@"Something found");
}
How can I change this for just the one using:
ObjectWithID: