NSFetchRequest with recursive criteria or recursive Fetched Property

299 Views Asked by At

In a sqlite based core data storage I have 2 entities: Item and Tag.

Item has a many to many relationship to Tag. Tag also has a recursive relationship for one parent tag. Hence tags form a tree.

Now I want to create a NSPredicate to fetch all items which have all the tags in a list of criteria tags.

The problem now is that the criteria should also be met if the item does not have a tag of the criteria list but a tag which is below the criteria tag in the tag tree.

I could expand the criteria list to include all descendants. But this would explode the list to enormous size as the tree a big.

One theoretic solution would be a Fetched Property in Tag "ancestors" which is "self joined with parent.ancestors". But I don't know how to formulate this. And I even think that it is not possible to traverse relationships in Fetched Properties, right?

For performance reasons I want to avoid to fetch all items and filter programmatically.

Any ideas?

Thanks, Marco

0

There are 0 best solutions below