1
votes

I have an entity called Attachment where it has a to-many relationship with no inverse relationship.

I am attempting to locate all Attachment entities whose downloaded attribute is NO the relationship name is attachments and I wrote the following predicate to do this.

[NSPredicate predicateWithFormat:@"ALL attachments.downloaded == NO"]

Which results in *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Unsupported predicate (null)'

This only happens on a SQLite store, if I change the store to Binary it seems to work fine. I would prefer to stick with a SQLite store.

Any ideas? Anyways to write the predicate differently to achieve the same desired result?

3

3 Answers

2
votes

This might be out of time, BUT still someone might still find the answer useful.

Currently, Core data using SQLite as the backend store DOES NOT support the ALL modifier. As simply as it sounds, that's why you can use it to filter the arrays in memory in order to achieve the desired results.

I think this is due to its 'difficulty' to implement. As for SQLite is concerned, it implements a Division operation on the conditional statement specified by the modifier. However, NSPredicate does not limit you to use it as part of a NSCompoundPredicate thus increasing the difficulty for the SQL generator to generate the SQL statement.

1
votes

Your schema description is a little unclear, but I believe you just want to execute the fetch on the Attachment entities with the predicate...

[NSPredicate predicateWithFormat:@"downloaded == NO"]

Have you tried that?

I might be totally wrong here ^_^

0
votes

I seem to have found a work around for now...

attachmentRequestResults = [self.managedObjectContext executeFetchRequest:attachmentIdRequest error:&error];
attachmentPredicate = [NSPredicate predicateWithFormat:@"ALL attachments.downloaded == NO"];
attachmentRequestResults = [attachmentRequestResults filteredArrayUsingPredicate:attachmentPredicate];

I removed the predicate for the fetchrequest so that it returns all entities and then I run my predicate on the returned array

Still looking for a solution where I can execute the predicate against Core Data though