I have two collections:
- Post
- Comment
Post.comments = [comment1, comment2, ...]
comment.removed is a boolean.
I’d like to fetch all Posts but exclude comments which are removed. Is there a way to do it without iterating over the OneToMany relationship ?
Here is what I tried:
ANY comments.removed == FALSE // Posts that have at least one removed comment
ALL comments.removed == FALSE // Posts that only have unremoved comments
(SUBQUERY(comments, $x, $x.removed == FALSE).@count > 0) // Same as the first one
If I understand your problem correctly, you would like to get all “Post” objects, but
post.commentsshould not be the entire set of comments as defined in the Core Data store, but only the set of comments that are not removed.This is not possible (as far as I know) with a fetch request, because the result of a fetch request is a list of objects in the managed object context. A fetch request can not return new objects that are different from their original in the managed object context.