NSPredicate for nested relationships

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.

enter image description here

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?

+7
ios core-data nspredicate
source share

No one has answered this question yet.

See similar questions:

nine
Core Data Predicate: Unrealized SQL Generation for a Predicate
4
NSPredicate for children

or similar:

26
NSPredicate - filter values ​​based on a stored BOOLEAN value
thirteen
NSPredicate formatting: ANY matching that meets two conditions
8
NSPredicate does not return results with a query for sampling, works with filtering arrays
7
Simple loading of kernel data is very slow
3
NSPredicate Intersection Relationship (StackMob)
2
NSPredicate Master Data with Multiple Relationships
one
Key data: NSPredicate relation containing to-many fails when using SQLITE storage type
0
How to create a lazy var for NSPredicate that can return nil
0
NSPredicate to detect non-empty relationships inside a subquery
0
Multiple NSPredicate

All Articles