Core Data inheritance and relationship
I have a following data model:
Entity User, which inherits from entity Contact.
Contact has one-to-one relationship with an entity ContactInfo.
User has one-to-many relationship to Contact.
ContactInfo has a reverse relationship to Contact and Contact in its turn has a reverse relationship to User.
I'm creating a ContactInfo object for User:
ContactInfo *moInfo = [self createContactInfoManagedObject];
moInfo.contact = userMO;
userMO.contactInfo = moInfo;
where createContactInfoManagedObject returns an object of type ContactInfo. I'm getting following exception on the line
moInfo.contact = userMO;
Unacceptable type of value for to-one relationship: property = "contact"; desired type = Contact; given type = NSManagedObject; value = <NSManagedObject: 0x3b2850> (entity: User; id: 0x3d4fa0 <x-coredata://4889CBE0-094B-49DB-B525-C87F7CD1AA68/User/p1> ; data: {
contacts = (
开发者_开发知识库 "0x3d4fa0 <x-coredata://4889CBE0-094B-49DB-B525-C87F7CD1AA68/User/p1>"
);
user = "0x3d4fa0 <x-coredata://4889CBE0-094B-49DB-B525-C87F7CD1AA68/User/p1>";
contactInfo = "0x3ebdc0 <x-coredata:///VCard/t128311BC-4B82-45CF-B87C-9AD38CBC89163>";
}).
My question is what's wrong here? I think something 's wrong with inheritance when I try to assign User entity to a contact relationship. Please advise! Thank you
Where is your userMO
object coming from?
The error message suggests it is an instance of NSManagedObject
, but it is expecting an instance of Contact
.
try to cast the object:
ContactInfo *moInfo =(ContactInfo*) [self createContactInfoManagedObject];
精彩评论