Core Data - 预测过滤关系子类
我有一个实体用户实体,它是朋友实体的父实体。
User 实体与名为 Article 的实体具有一对多关系。
这个想法是保存了用户和朋友(来自 Facebook),与 Article 的一对多关系在 User 实体上设置,因为这是 Friend 的子类。
我的问题是如何请求朋友的所有文章而不是所有用户的文章?
我在设置预测以忽略用户实体并仅保留朋友实体时遇到问题。
谢谢。
I have an entity User entity which is a parent entity to a Friend entity.
The User entity has a to-many relationship with an entity named Article.
The idea is there are users saved and also friends (from Facebook), the to-many relationship to Article is set on the User entity as this is being subclassed by Friend.
My question is how can I request all Articles by Friends and not by all users ?
I am having trouble setting an Predict to omit User entities and keep only Friend entities.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您在这里构建父/子实体设计有什么原因吗?如果您坚持使用 sqlite 存储,父/子实体会带来非常沉重的成本。只拥有一个实体并有一个标志表明它是否是朋友几乎总是一个更好的主意。
另外,我知道在数据库级别没有办法在这个设计中从子级中过滤掉父级。它可以在获取后通过请求
entity.name
在内存中完成,但这不会正确地变成 sql 调用。Is there a reason you are building a parent/child entity design here? Parent/Child entities come with a really heavy cost if you are persisting to a sqlite store. It is almost always a better idea to just have a single entity and have a flag stating if it is a friend.
Also, I know of no way, at the database level, to filter out the parent from the child in this design. It can be done in memory after the fetch by requesting the
entity.name
but that will not turn into a sql call properly.