我有一个要保存 2 个实体的属性值的视图:根啤酒和评论。这些值具有反比关系,但由于某种原因,仅保存评级值。有人能告诉我我做错了什么吗?或者,应该做不同的事情?
NSManagedObjectContext *context = [self managedObjectContext];
Comments* com = [NSEntityDescription insertNewObjectForEntityForName:@"Comments" inManagedObjectContext:context];
RootBeer* rootBeer = [NSEntityDescription insertNewObjectForEntityForName:@"RootBeer" inManagedObjectContext:context];
//save root beer values
[rootBeer setValue:self.rootBeerNameField.text forKey:@"rootBeerName"];
[rootBeer setValue:self.rootBeerBrewerField.text forKey:@"rootBeerBrewer"];
[rootBeer setValue:self.rootBeerLocationField.text forKey:@"rootBeerLocation"];
[rootBeer setValue:self.rootBeerDetailField.text forKey:@"rootBeerDetails"];
//save root beer comments/notes
[com setValue:self.rootBeerNotes.text forKey:@"rootBeerComment"];
[rootBeer setValue:com forKey:@"comments"];
//This is the only value that is being stored
[rootBeer setValue:[NSNumber numberWithFloat:rateView.rate]forKey:@"myRootBeerRating"];
NSError* error = nil;
if(![context save:&error]){
NSLog(@"Can't Save! %@ %@", error, [error localizedDescription]);
}
NSLog(@"Saved!");