这是谓词:
group.AddressElements CONTAINS <AddressElement: 0x18a4b610> (entity: AddressElement; id: 0xb76dc60 <x-coredata://4F0D8450-8BB8-4361-AF55-69ED35799058/AddressElement/p2468> ; data: <fault>)
粗略地说,我想检索与组具有一对一关系的实体,并且该组与AddressElement实体具有to-many关系。我想要检索的对象必须在相关组的AddressElements中具有特定的AddressElement对象。因此我编写了谓词:group.AddressElement必须包含我作为参数传递的对象,即<AddressElement: 0x18a4b610> (entity: AddressElement; id: 0xb76dc60 <x-coredata://4F0D8450-8BB8-4361-AF55-69ED35799058/AddressElement/p2468> ; data: <fault>)
当我尝试获取请求时,我发生了针对谓词异常的未实现SQL生成的崩溃。
我做错了什么?
答案 0 :(得分:2)
正如您所看到的,here contains
关键字用于字符串比较。
尝试将谓词修改为(未测试):
修改强>
我测试了两个:
[NSPredicate predicateWithFormat:@"ANY group.AddressElements = %@",someAddressElement]
和
[NSPredicate predicateWithFormat:@"%@ IN manufactur.manufactures",someAddressElement]
两者都产生以下SQL语句:
SELECT DISTINCT 0, t0.Z_PK, t0.Z_OPT, t0.ZSOMEPROP, t0.ZTOONE FROM ZSOMEENTITY t0 JOIN ZTHEONEENTITY t1 ON t0.ZTOONE = t1.Z_PK JOIN ZTHEMANY t2 ON t1.Z_PK = t2.ZTOMANY WHERE t2.Z_PK = ?
(在iOS 6.1上测试)