Subject
s とs の2 種類のエンティティがありCorrespondent
ます。それらは両方とも、対多の関係を介して互いに関連しています。返される にfetchRequest
渡すことができるシングルが必要です。NSFetchedResultsController
subject
複数の を持つすべてのcorrespondent
。- それらだけが離れている
correspondent
を持つすべての。subject
Subject
さまざまなことを試した後、 s とs の両方を返す単一のフェッチを作成することは不可能であると判断したため、Correspondent
StackOverflow に目を向けると、返したい 2 つのエンティティ。
そこで、3 番目のタイプのエンティティーを作成しました。これを s と呼びました。それぞれのエンティティーには、 aおよび a とFolder
のオプションの対 1 関係があります。また、との 2 つの属性があります。これらは、またはが設定されているかどうかを追跡するブール値です。Subject
Correspondent
hasCorrespondent
hasSubject
Subject
Correspondent
Folder
そこで、エンティティを返す次の述語を書きました。
(hasCorrespondent == 1 AND ANY correspondent.subjects.correspondents.@count == 1)
OR
(hasSubject == 1 AND subject.correspondents.@count >= 1)
これに関する問題は、エラーが発生することです:
Terminating app due to uncaught exception 'NSInvalidArgumentException',
reason: 'Unsupported function expression count:(correspondent.subjects.correspondents)
それで、私が間違っていることについて何か提案はありますか?どうすればやりたいことを達成できますか? 共有すべき追加の詳細はありますか?
アップデート
マーティンの提案により、問題のある部分を次のように変更しました。
SUBQUERY(correspondent.subjects, $s, $s.correspondents.@count == 1).@count > 0
しかし、それは新しいエラーを生成しました:
Keypath containing KVC aggregate where there shouldn't be one;
failed to handle $s.correspondents.@count
グーグルで調べた後、列挙されているコレクションに少なくとも1つのオブジェクトがあることを確認するための提案を見つけましたが、問題のある行をこれに変更してもエラーメッセージは変わりませんでした(私が知る限り、何もしなかったと言えます):
correspondent.subjects.@count > 0 AND
SUBQUERY(correspondent.subjects, $s, $s.correspondents.@count == 1).@count > 0