Reputation: 6593
Is it possible to define a relationship in Core data based on more than one column?
For instance I have an Entity called Error with attributes: Name and Id. I have two other entities X and Y. Both X and Y have a one to many relationship with Error. Errors related to X have Name 'X' and Id equal to a primary key in X. Errors related to Y have Name 'Y' and Id equal to a primary key in Y.
Is it possible to define relationships of this nature in core data?
Upvotes: 0
Views: 116
Reputation: 8988
Yes, if you define an abstract class Z with a relationship 'errors' with Errors and then define X and Y as classes that inherit from Z both will have a relationship 'errors'.
Just remember Core Data does not use foreign keys, you set the relationship attribute directly.
newError.parent = objectX
And to get all X errors
for ( Error *error in objectX.errors) {
NSLog(@" error is %@, %@", error.id, error.name");
}
Upvotes: 0