关于核心数据获取属性的两个基本问题
假设我有两个实体:课堂和学生。课堂与学生是一对多的关系。每个学生都有一辆车(hascar 为 1)或没有(hascar 为 0)
我想在课堂上创建几个获取的属性:
- 拥有汽车的学生数量
- 学生
数量令我困惑的是语法。如何构建一个谓词来检查特定教室中的所有学生?
谢谢你!
Let's say I have two entities: Classroom and Student. The Classroom has a to-many relationship with student. Every student has a car (hascar is 1) or does not (hascar is 0)
I would like to create a couple of fetched properties on Classroom:
- number of students that have a car
- number of students
What is tripping me up is the syntax. How do I build a predicate that examines all of the students in a particular classroom?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不需要获取或获取的属性来检查与特定教室相关的所有学生,因为该关系会自动找到学生。
假设您有一个特定的 ClassRoom 对象,aClassRoom。键 aClassRoom.students 返回所有相关 Student 对象的 NSSet。然后你需要做的就是使用集合运算符来获取你想要的信息。
学生的数量很简单:
拥有汽车的学生的数量:
如果您有某种关系,那么您不需要通过获取来查找有关该关系中的对象的信息。
You don't need a fetch or a fetched property to examine all the students related to a particular classroom because the relationship finds the students automatically.
Suppose you have a particular ClassRoom object, aClassRoom. The key aClassRoom.students returns a NSSet of all the related Student objects. All you need to do then is to use collection operators to get the information you want.
The number of students would be simple:
The number of students with cars:
If you have a relationship, you don't ever need a fetch to find something about the objects in that relationship.