iphone 子对象的谓词
我在谓词编程指南中看到这一点:
如果使用一对多关系,谓词的构造会略有不同。例如,如果要获取其中至少有一个员工的名字为“Matthew”的部门,则可以使用 ANY 运算符,如下例所示:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"ANY employees.firstName like 'Matthew'"];
通过上述构造,它将返回包含所有员工的部门与其关联的对象,前提是至少有一名员工的名字为“Matthew”。
我想修改它以仅获取名字为“Matthew”的员工。 因此,如果该部门只有 2 名员工与该名字匹配,则只应返回 2 个员工对象。
我怎样才能实现这个目标? 谢谢。
I see this in the predicate programming guide:
If you use a to-many relationship, the construction of a predicate is slightly different. If you want to fetch Departments in which at least one of the employees has the first name "Matthew," for instance, you use an ANY operator as shown in the following example:
NSPredicate *predicate = [NSPredicate predicateWithFormat:
@"ANY employees.firstName like 'Matthew'"];
With the above construction, it would return the department with all employees objects associated to it, provided at least one of the employees have first name as 'Matthew'.
I would like to modify this to fetch ONLY those employees with first name as 'Matthew'.
So if the department has only 2 employees matching this first name, only 2 employee objects should be returned.
How can I achieve this?
thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在对一组
Department
对象执行此操作,因此您只能取回Department
对象。如果您想要Employee
对象,则必须执行以下操作:此外,由于您的
LIKE
过滤器没有任何?
或者其中包含*
符号,相当于“isEqual:”比较。You're executing this agains a set of
Department
objects, so you can only get backDepartment
objects. If you wantEmployee
objects instead, you'd have to do something like this:Also, since your
LIKE
filter doesn't have any?
or*
symbols in it, it is equivalent to an "isEqual:" comparison.