自动生成谓词行模板的多对一键? [英] Automatically generated predicate row templates for to-many key?

查看:186
本文介绍了自动生成谓词行模板的多对一键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Core Data托管对象模型中,我有一个实体Foo,它与一个名为baz的实体Baz具有一对多关系(一对多的逆)。 Baz有一个名为tag的字符串属性。当我使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:[NSArray arrayWithObject:@baz.tag] inEntityDescription:FooDescription] 为NSPredicateEditor创建行编辑器,结果包含)一个行模板如



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



当我从弹出窗口中选择Contains时,带有谓词的查询按预期工作。如果我选择任何其他弹出窗口(例如是),我得到以下错误:许多密钥不允许在这里。我可以使用 [NSPredicateRowEditorTemplate templatesWithAttributeKeyPaths:inEntityDescription:] 或者我必须手动构建行编辑器吗?

它看起来像自动生成的模板(使用 [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]; 


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?

解决方案

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

这篇关于自动生成谓词行模板的多对一键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆