Core Data can't do Distinct Relationships to Same Entity
Core Data can't do Distinct Relationships to Same Entity
- Subject: Core Data can't do Distinct Relationships to Same Entity
- From: Jerry Krinock <email@hidden>
- Date: Tue, 22 Jun 2010 19:12:09 -0700
Say that I'm modelling a human body. Each body has two arms, and I model them with the same entity; one has, maybe, setFlipped:YES and the other has setFlipped:NO. But they are accessed for different purposes; sometimes I want the left arm and sometimes the right arm. I'd therefore like to set up relationships thus:
Body_Entity Arm_Entity
leftArm <----> body
rightArm <----> body
But Core Data won't let me do this, because the Arm's 'body' relationship can only have one inverse relationship. Instead, I must do this:
Body_Entity Arm_Entity
leftArm <----> bodyLeft
rightArm <----> bodyBody
which looks kind of silly, and also in order to access 'body' from an Arm object I need a silly accessor:
- (Body*)body {
Body* body = [self bodyLeft] ;
if (!body) {
body = [self bodyRight] ;
}
return body ;
}
Is there a better way to model such a thing?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden