Automatically generated predicate row templates for to-many key?

这一生的挚爱 提交于 2019-12-07 15:55:36

问题


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:


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];


来源:https://stackoverflow.com/questions/210735/automatically-generated-predicate-row-templates-for-to-many-key

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!