views:

429

answers:

1

In my Core Data managed object model, I have an entity Foo with a to-many relationship (with a to-many inverse) to entity Baz named baz. Baz has a string property named "tag". When I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@"baz.tag"] inEntityDescription:FooDescription] to create the row editors for an NSPredicateEditor, the result contains (as expected) a row template like

[Popup: baz.tag] [Popup: Contains|is|is not|...] [TextField]

When I select "Contains" from the popup, a query with the predicate works as expected. If I choose any of the other popups (e.g. "is"), I get the following error: "to-many key not allowed here". Can I use [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] or do I have to build the row editor manually?

+1  A: 

It looks like the automatically generated template (using [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]) cannot produce the correct operators. The solution is to create the template manually using [NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:]. For the given example:

id template = [[NSPredicateEditorRowTemplate initWithLeftExpressions:[NSArray arrayWithObject:[NSExpression expressionForKeyPath:@"baz.tag"]] rightExpressionAttributeType:NSStringAttributeType modifier:NSAnyPredicateModifier operators:keywordOperators options:0];
Barry Wark