开发者

NSPredicate by NSManagedObject for many-to-one lookups

开发者 https://www.devze.com 2022-12-25 07:18 出处:网络
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'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 mak开发者_如何学Goe 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


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.

That would be myArm.owner. No predicate needed; this is what the inverse relationship is for.

0

精彩评论

暂无评论...
验证码 换一张
取 消