在 CoreData 中获取不同的 ID 列表
在 CoreData 表上执行此查询的最有效方法是什么?要使用标准员工数据库模型,我希望包含职位描述为“厨师”的员工的所有部门都有不同的部门 ID。碰巧,这里只有一个相关的表(员工)——我实际上没有部门表,只有重复的部门 ID。
What's the most efficient way to perform this query on a CoreData table? To use the standard employees database model -- I want DISTINCT department ID's for all departments that contain employees with job-description "chef." As it happens, there is only a single table (Employees) relevant here -- I don't actually have a departments table, just department ID's that are repeated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
给定您描述的模式,我将使用诸如
@"jobDescription LIKE 'chef'"
之类的谓词(格式字符串)执行提取,然后使用键值编码从结果数组中获取唯一值:或创建一组:
根据问题的大小(有多少员工),在内存中执行最后一步可能会令人望而却步。此时,您必须创建一个部门实体并进行工作以确保将适当的员工连接到每个部门。然后,您可以使用诸如
@"ANYEmployees.jobDescription LIKE 'chef'"
这样的谓词(格式字符串)来获取部门,以获取具有厨师员工的部门。Given the schema you describe, I would execute a fetch with a predicate (format string) like
@"jobDescription LIKE 'chef'"
and then use key-value coding to get the unique values from the resulting array:or create a set:
Depending on the size of the problem (how many employees), doing the final step in-memory may prove prohibitive. At this point, you'll have to create a Department entity and do the work to make sure you connect appropriate employees to each department. Then you can do a fetch of Departments with a predicate (format string) like
@"ANY employees.jobDescription LIKE 'chef'"
to get the departments with chef employees.