0

I have a Category entity with Scan child entities (one to many relationship). Now I would like to fetch all Categories with a running a predicate on the children.

Details: Category has a child relationship of Scans which is a Set. Scan has an isSent bool which I want to use in the predicate.

I want to fetch all Categories but filter the Scan children by isSent = true.

This code does not work:

let scans: FetchRequest<Scan>
scans = FetchRequest<Category>(entity: Category.entity(), sortDescriptors: [
        ], predicate: NSPredicate(format: "scans.isSent = %d", true))

Is there any way to write a FetchRequest with using a predicate on the children?

Thanks!

Pete
  • 213
  • 1
  • 13
  • If you want to fetch all Scans object where isSent is true then it’s better to directly fetch from Scans. – Joakim Danielson Sep 16 '22 at 15:00
  • Thanks, I think that is the way I will go. I just thought it would have been more elegant if I could filter on child objects. – Pete Sep 19 '22 at 05:57

0 Answers0