I have a many-to-many relationship between two entities (EntityA and EntityB) in Core Data, and I'm trying to clean up the database periodically by removing instances of EntityB that no longer have any relationships to any instances of EntityA. I'm using Mogenerator to create the .m and .h files, which allows me to reference attribute/relationship names the way I do.
NSPredicate *noRelationPredicate = [NSComparisonPredicate predicateWithLeftExpression:[NSExpression expressionWithFormat:@"%K", EntityBRelationships.relationshipNameForEntityA] rightExpression:[NSExpression expressionWithFormat:@"nil"] modifier:NSDirectPredicateModifier type:NSEqualToPredicateOperatorType options:0];
However, I'm encountering the following error when I perform the fetch: 'NSInvalidArgumentException', reason: 'to-many key not allowed here'
I'd prefer creating the predicate using the class method NSComparisonPredicate predicateWithLeftExpression:rightExpression:modifier:type:options: as I try to avoid string literals in predicate creation.