I'm trying to build a single NSFetchRequest
predicate for the following (simplified) model:
There is a simple to-many relationship between a
Category
and a number ofBrand
s.Each
Brand
then has amodelNumbersData
property which is binary data, a serialisation of an array ofNSString
modelNumbers which are exposed in a transient property on theBrand
objects.There is no direct relationship between
Brand
s andModel
s. The relationship is that aModel
'smodelNumber
may be in aBrand
'smodelNumbers
transient property.
I would like to build an NSPredicate
query to fetch all of the Model
objects under a particular Category
.
Fetching the Model
s for a Brand
is easy, I can do "modelNumber IN $FETCH_SOURCE.modelNumbers"
. How do I now extend this query to originate with the category? It seems I need a SUBQUERY
?
Furthermore, I am doing an NSFetchRequest
, so unless I'm mistaken I need to start with "SELF.modelNumber IN (...)"
, so that we select from all Model
s.
Thanks in advance!
Model
s, I can filter for what I want with:SUBQUERY(%@.brands, $brand, $brand.modelNumbers CONTAINS SELF.modelNumber).@count > 0
But how can I combine this into a single step/query? Seems it needs to be the other way around... - Jonathan Crooke