I'm having trouble formatting a predicate to find nested relationships in master data. I came across some very similar questions / comments that I hoped would help me find the right solution, but I was still stuck.

I am trying to create a select query to search for all Foo instances associated with a specific gadget instance.
First I tried using the predicate for fetchRequest for the Foo object:
[NSPredicate predicateWithFormat:@"ANY bar.widgets.gadget == %@", myGadget]
but this fetch query returns 0 results. I guess it is because of the relationship nested to many.
I think I need to use a subquery that I have never had to use before. After much research and reading, I tried
[NSPredicate predicateWithFormat:@"SUBQUERY(bar.widgets, $w, ANY $w.gadget == %@) .@count > 0", myGadget]
And I get an error
SQLite error code: 1, "no such column: t2.ZGADGET"
So, I correctly understood that I need a subquery for this scenario, and if so, how to format it correctly?
ios core-data nspredicate
alivingston
source share