NSPredicate by NSManagedObject 用于多对一查找
我有两个 NSManagedObjects(Arm 和 Person)的场景。他们之间是多对一的关系Person.arms和逆Arm.owner。
我想编写一个简单的 NSPredicate,其中我有 NSManagedObject *arm
并且我想获取该手臂所属的 NSManagedObject *person
。我可以制作文本表示并查找它,但是有没有更好的方法可以通过身份查找它?也许是这样的?
NSEntityDescription *person = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:MOC];
NSPredicate *personPredicate = [NSPredicate predicateWithFormat:@"%@ IN arms", arm];
干杯
尼克
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
那将是
myArm.owner
。不需要谓词;这就是逆关系的用途。That would be
myArm.owner
. No predicate needed; this is what the inverse relationship is for.