核心数据谓词:谓词的未实现 SQL 生成 [英] Core Data predicate : unimplemented SQL generation for predicate
问题描述
基本上我的数据模型中有 3 个实体:Brand、Model 和 Trim.
Basically I got 3 entities in my data model : Brand, Model and Trim.
- 品牌与模特之间存在一对多关系,称为模特".(一个品牌有多个型号,但一个型号只有一个品牌)
- 模型与 Trim 之间存在多对多关系,称为trims".(一个模型可以有多个修剪,一个修剪可以有多个模型)
拥有一系列修剪对象,我希望所有品牌都拥有一个模型,该模型包含"至少一个包含在该数组中的修剪.
Having an array of trims objects, I would like to get all the brands having a model which "contains" at least one trim contained inside this array.
所以这是我对获取请求的谓词:
So here is my predicate for the fetch request :
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Brand"];
[NSPredicate predicateWithFormat:@"ANY models.trims IN %@", arrayOfTrims];
这是我得到的错误:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'unimplemented SQL generation for predicate : (ANY models.trims IN {<Trim: 0x8e60340> (entity: Trim; id: 0x8e62f10 <x-coredata://BCD28560-AED5-4409-9A35-1925001773E6/Trim/p8>
我对 Core Data 有点陌生,不知道自己做错了什么.
I'm kinda new to Core Data and I have no idea what I'm doing wrong.
希望有人能帮忙,
非常感谢.
推荐答案
ANY" 在 Core Data 谓词中仅适用于单对多关系.由于您的查询涉及两个对多关系,您必须使用子查询:
"ANY" in a Core Data predicate works only for a single to-many relationship. Since your query involves two to-many relationships, you have to use a SUBQUERY:
[NSPredicate predicateWithFormat:@"SUBQUERY(models, $m, ANY $m.trims IN %@).@count > 0",
arrayOfTrims];
这篇关于核心数据谓词:谓词的未实现 SQL 生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!