Background
I've got a core data database made of two stores (one repository for my data and one store for the user data), linked between them by fetched properties.
Let's say I have two entities such that the relationship between them is 0 to 1. Card 0 ----> 1 CardStatus
1) Card, containing reference data and some properties (externalKey, word, description, ...)
Fetch Properties - userData (pointing to CardStatus and using the externalKey to do the link between the 2 entities)
2) CardStatus, containing the status of each Card. This entity is stored in the user data store.
There are cases where I need to fetch cards based on their status (example: retrieve all the cards that are marked as expired, retrieved all the cards that are marked as new, etc...)
Question
What kind of predicate should I write to fetch Card entities based on values from the CardStatus entity?
I tried using my fetched property userData directly in the predicate, but it's not allowed by core data.
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'keypath userData not found in entity '
Then I tried with a subquery (see below) - still doesn't work. Interestingly, it works fine when I do a filter directly on an NSArray (instead of a fetch request).
Example - Retrieving card with a specific status:
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"(SUBQUERY(userData, $x, ($x.currentLevel == 0)).@count > 0)"];
Example - Retrieving card marked as new (i.e. no data in CardStatus):
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SUBQUERY(SELF, $x, $x.userData.@count == 0).@count > 0"];
Any suggestion?