NSPredicate by NSManagedObject for many-to-one lookups

Posted by niklassaers on Stack Overflow See other posts from Stack Overflow or by niklassaers
Published on 2010-04-03T14:17:50Z Indexed on 2010/04/03 14:23 UTC
Read the original article Hit count: 331

Filed under:
|
|

Hi guys,

I've got the scenario with two NSManagedObjects, Arm and Person. Between them is a many-to-one relationship Person.arms and inverse Arm.owner.

I'd like to write a simple NSPredicate where I've got the NSManagedObject *arm and I'd like to fetch the NSManagedObject *person that this arm belongs to. I could make a textual representation and look for that, but is there a better way where I can look it up by identity? Something like this perhaps?

NSEntityDescription *person = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:MOC];
NSPredicate *personPredicate = [NSPredicate predicateWithFormat:@"%@ IN arms", arm];

Cheers

Nik

© Stack Overflow or respective owner

Related posts about predicate

Related posts about core-data