有点复杂 NSPredicate (IOS)ha
现在,我需要对 NSFetchRequest 使用谓词。
但这里的情况有点不同,因为谓词要经历两个嵌套对多关系。
例如,我的实体是这样的:
现在我需要获取一些月和周 ManagedObjects,但是要求是所需周或月中一天的事件数量多于一个。
换句话说,对于给定的周或月,如果其“天”关系的目的地上的任何一天至少有一个事件,则接受它。
所以这是一个嵌套的多对多关系,我不知道如何设置谓词字符串。
有两个麻烦:
我知道 ALL 和 ANY 关键字。但是@“ANY days.ANY events”可以是关键路径吗?或者应该如何?
如何判断事件关系至少指向一个Event对象。
[@"%K != nil",theCorrectKeypath]
有效吗?我担心“!= nil”不等于至少一个目标对象?
等待有人来帮助我。
非常感谢!
Now, I need to use a predicate for a NSFetchRequest.
But things here are a little different, since there are two nested to-many relationships for the predicate to go through.
For instance, my entities are like this:
Now I need to fetch some Month and Week ManagedObjects, but the requirement is that the amount of Events of a Day of the needed Weeks or Months is more than one.
In another word, with reference to a given Week or Month, if any Day on the destination of its "days" relationship has at least one Event, then take it.
So that is a nested to-many relationship, and I don't know how to set the predicate string.
There are two troubles:
I know ALL and ANY keyword. But could
@"ANY days.ANY events"
be the keypath? Or how is it supposed to be?How to judge that the events relationship points to at least one Event object.
Would [@"%K != nil",theCorrectKeypath]
work? I'm afraid of that "!= nil" does not equal to at least one destination object?
Waiting for someone to help me out.
Terribly thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我自己找到了答案。
还有另一种方法可以得到这个,因为我的条件,我可以只谓词合适的Events对象,并且从Events到Week或Month都是一对一的关系,
所以一旦我得到了符合条件的Events,
我就可以得到相应的 划分的周和月
按Event.date.thisWeek 或theEvent.date.thisMonth
。谢谢你们,
I found the answer my self.
There's another way to get this, because of my condition, I can just predicate the suitable Events objects, and all the way from Events to Week or Month are to-one relationship,
so once I got the eligible Events,
I can just get corresponding Weeks and Months by
theEvent.date.thisWeek or theEvent.date.thisMonth.
Thanks for your guys,