2008-10-17 66 views
2

在我的核心数据管理对象模型中,我有一个实体Foo,它与实体Baz命名为baz的多对多关系(具有对多个逆)。 Baz有一个名为“tag”的字符串属性。当我使用[NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@"baz.tag"] inEntityDescription:FooDescription]为NSPredicateEditor创建行编辑器时,结果包含(如预期的)行模板,如为多对多关键字自动生成谓词行模板?

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

当我从弹出窗口中选择“Contains”时,带谓词的查询按预期工作。如果我选择其他弹出窗口(例如“is”),则会出现以下错误:“此处不允许使用多对多密钥”。我可以使用[NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:]还是必须手动构建行编辑器?

回答

3

它看起来像自动生成的模板(使用[NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:])不能产生正确的操作符。解决方案是使用[NSPredicateEditorRowTemplate initWithLeftExpressions:rightExpressionAttributeType:modifier:operators:options:]手动创建模板。对于给定示例:

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