ios - NSPredicate complex query -
i've got complex nspredicate
problem cannot solve.
my data structure follows:
category - has many titles
title - has many products
title - has latestproduct property (title.latestproduct
)
titles can excluded via excluded property (title.excluded = yes
) products can excluded via excluded property (product.excluded = yes
)
the result looking for: need fetch list of categories in system, want exclude categories where:
- all category titles excluded
(category.titles.excluded == yes)
or
- all latest products excluded (
category.titles.latestproduct.excluded == yes
)
or (and tough part me)
- the sum of count of (
category.titles.excluded == yes
) , count of (category.titles.latestproduct.excluded == yes
) equal count of category titles (category.titles.count
)
i can describe problem in plain english cannot work out proper way format predicate. appreciated thanks!
so worked out way using combination of clause subquery. predicate follows:
any producttitles.excluded == nil && subquery(producttitles, $x, subquery($x.products, $y, $y.excluded == nil).@count != 0 ).@count != 0
i think subquery how "any" clause works anyway not figure out how clause subquery of subquery.
Comments
Post a Comment