How to get objects of related indirectly by NSPredicate?

10 Views Asked by At

I have three model in CoreData:

  • Category with categoryId
  • Production with productionId
  • SubProduction with subProductionId

SubProduction is related to One Production and every product has Many SubProduction

Production is related to One Category and every Category has Many Production

I want to get all SubProduction of a Category by categoryId.

I know this way: Load all productions of category and by a for loop get all SubProductions. I'm wondering if there is a better way to approach it by NSPredicate

How to make this NSPredicate format?

Something like this:

frc.fetchRequest.predicate = NSPredicate(format: "production.category = %@", category)
1

There are 1 best solutions below

0
On BEST ANSWER

WOW, I just test my imagine and

It's work:

frc.fetchRequest.predicate = NSPredicate(format: "production.category = %@", category)

Thanks to NSPredicate