Core Data Null Relationship
Posted
by Dylan Copeland
on Stack Overflow
See other posts from Stack Overflow
or by Dylan Copeland
Published on 2010-03-14T17:36:20Z
Indexed on
2010/03/14
20:35 UTC
Read the original article
Hit count: 314
I have a to-one relationship in my data model with Core Data. I'm trying to set the value of the relationship but Core Data keeps thinking that it's nil. The "creatorUser" relationship is not optional, so when I go to save my managed object context, Core Data gives errors because it thinks the "creatorUser" is nil.
Any help would be greatly advised.
NSManagedObject *teamManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"DCTeam" inManagedObjectContext:_managedObjectContext];
// Creator Properties
NSManagedObject *creator = [self userForID:[ticketInfo objectForKey:@"userid"]];
if (!creator) {
creator = [NSEntityDescription insertNewObjectForEntityForName:@"DCUser" inManagedObjectContext:_managedObjectContext];
[creator setValue:[personInfo objectForKey:@"userid"] forKey:@"userid"];
[creator setValue:[personInfo objectForKey:@"creatorName"] forKey:@"name"];
}
[teamManagedObject setValue:creator forKey:@"creatorUser"];
© Stack Overflow or respective owner