[英]Fetch request CoreData from relationship
This is the situation, I have two entities in CoreData. 这种情况,我在CoreData中有两个实体。
And this is how they are related: 它们是如何关联的:
The final result I want is something like this... 我想要的最终结果是这样的...
Fetch questions WHERE chapter = <some> and (LAST) answer.correct = YES
I'm kind of new with core data and right now I'm doing it with many steps but I wanted to know if I can achieve this with only one NSFetchedResultsController without filtering arrays. 我对核心数据有点陌生,现在我正在执行很多步骤,但是我想知道是否可以仅使用一个NSFetchedResultsController而不过滤数组来实现。
Thank you very much for your help! 非常感谢您的帮助!
Try this predicate. 试试这个谓词。 May work for you.
可能为您工作。
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chapter = '%@' AND answer[LAST].correct=TRUE",chapterName];
A little convoluted, but I think the following will get what you want: 有点令人费解,但我认为以下将满足您的要求:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"chapter like %@ AND (SUBQUERY(answer, $t, $t.correct == YES).date.@max = SUBQUERY(answer, $t, $t.correct IN {YES, NO}).date.@max)"];
This checks whether the maximum date for correct answers is equal to the maximum date for all answers. 这将检查正确答案的最大日期是否等于所有答案的最大日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.