Reputation: 454
I have a model like this Product ---> Options (One-to-many relationship, no -invers)
Option -------> Size (one - to - one relationship, no-invers)
Option -------> sold_out (attribute,BOOLEAN)
Now I want to fetch an array of all sizes of all options of all products where option.sold_out is NO.
How can I use Predicates to fetch it from Core Data rather than iterating through arrays of products an options
Upvotes: 0
Views: 717
Reputation: 5966
First NEVER use one-way relationships in Core Data. You may not use it by yourself, but Core Data need it for referential integrity.
Why does an entity need an inverse?
Now,about your request. You could use something like this.
request.entity = [NSEntityDescription entityForName:@"Product" inManagedObjectContext:managedObjectContext];
request.prdicate = [NSPredicate predicateWithFormat:@"ANY option.sold_out == %@",[NSNumber numberWithBool: YES]];
Now,it's you, who need the inverse — because there is no adequate way for you to do this request without Size---->Option relationship. If you had one, let's call it option,you could do your request like this:
request.entity = [NSEntityDescription entityForName:@"Size" inManagedObjectContext:managedObjectContext];
request.prdicate = [NSPredicate predicateWithFormat:@"option.sold_out == %@",[NSNumber numberWithBool: YES]];
Upvotes: 1