不包含实体的多对多关系的谓词
Predicate for many to many relationships not containing entity
我在相同实体之间有 2 个多对多关系:
Document <<-->> Code // As documents
Document <<-->> Code // As preattachedToDocuments
我有两个核心数据提取,它们得到相反的代码集作为结果。第一个有效,但是第二个 returns 没有结果:
// Gives desired results
// Desired: Set of all codes that are attached to the document
[NSPredicate predicateWithFormat:@"%@ IN documents || %@ IN preattachedToDocuments", _document, _document];
// Gives no results
// Desired: Set of all codes not attached to the document
[NSpredicate predicateWithFormat:@"NOT (%@ IN documents || %@ IN preattachedToDocuments)", _document, _document];
本次提取时文档本身可能是空的,并且缺少任何标识属性或 ID。我可以使用什么谓词来给出当前未附加到文档的所有代码?
嗨,我想你想要的是它应该在文档中,而不是在预取的文档中。
[NSpredicate predicateWithFormat:@" %@ IN documents &&(NOT %@ IN preattachedToDocuments)", _document, _document];
希望对您有所帮助
尝试使用 SUBQUERY:
[NSPredicate predicateWithFormat:@"(SUBQUERY(documents, $doc, $doc == %@).@count == 0) && (SUBQUERY(preattachedToDocuments, $att, $att == %@).@count == 0)", _document, _document];
我在相同实体之间有 2 个多对多关系:
Document <<-->> Code // As documents
Document <<-->> Code // As preattachedToDocuments
我有两个核心数据提取,它们得到相反的代码集作为结果。第一个有效,但是第二个 returns 没有结果:
// Gives desired results
// Desired: Set of all codes that are attached to the document
[NSPredicate predicateWithFormat:@"%@ IN documents || %@ IN preattachedToDocuments", _document, _document];
// Gives no results
// Desired: Set of all codes not attached to the document
[NSpredicate predicateWithFormat:@"NOT (%@ IN documents || %@ IN preattachedToDocuments)", _document, _document];
本次提取时文档本身可能是空的,并且缺少任何标识属性或 ID。我可以使用什么谓词来给出当前未附加到文档的所有代码?
嗨,我想你想要的是它应该在文档中,而不是在预取的文档中。
[NSpredicate predicateWithFormat:@" %@ IN documents &&(NOT %@ IN preattachedToDocuments)", _document, _document];
希望对您有所帮助
尝试使用 SUBQUERY:
[NSPredicate predicateWithFormat:@"(SUBQUERY(documents, $doc, $doc == %@).@count == 0) && (SUBQUERY(preattachedToDocuments, $att, $att == %@).@count == 0)", _document, _document];