用于选择具有关系子集的项目的谓词
我有一个包含日期列表(“Day”对象)的数据库。
每天都有一个事件列表(一对多)
如何编写获取谓词以获取名称=='星期一'的全天对象,并且仅包含时间> 的事件。 aStartTime 和 time <结束时间?
或者换句话说......
我想要一个“星期一”对象数组,其中 day.events 仅包含特定时间间隔的事件。
I have a DB with a list of days ('Day' objects).
Each day has a list of events (one-to-many)
How do I write a fetch predicate in order to fetch all day objects where name=='Monday' and only include the events where the time is > aStartTime and time < aEndTime?
Or in other words....
I want an array of 'Monday' objects where day.events only contains the events for a certain time interval.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果不添加新的 Day 对象就不行;它违背了核心数据(对象图/变更管理)的全部要点。如果每个事件只能有一天,那就会变得混乱。
或者,您可以返回某种“代理”Day 对象,但这不会完全做同样的事情(但它可能更接近您正在寻找的东西)。
或者,在每个事件中,存储 0 到 60*60*24*7 之间的数字,执行查询,然后根据需要对结果进行排序。
或者,告诉我们您实际想要实现的目标,我们也许能够给出更好的答案。
You can't without adding new Day objects; it goes against the whole point of Core Data (object graph/change management). And if each event can only have one Day, it gets messy.
Alternatively, you can return some sort of "proxy" Day objects, but that won't quite do the same thing (it might be closer to what you're looking for, though).
Alternatively, in each event, store a number between 0 and 60*60*24*7, do the query, and sort the results however you like.
Alternatively, tell us what you're actually trying to achieve and we might be able to give a better answer.