邯郸土包子
邯郸土包子

Reputation: 3

How to use Coredata NSPredicate like 'left join' in sql

CoreDataModel:(I put JSONFORMAT HERE.)

Questions [{qid:1,comments:[{cid:1,user:{'uid':3}},{cid:2,user:{'uid':4}}]},
           {qid:2,comments:[{cid:1,user:{'uid':4}},{cid:2,user:{'uid':5}}]}]

Question has relation with comments one2many, comment has one2one relation with user.

How do I search the question which had been commentd by the user (uid=1), using NSPredicate?

below is my model pic

enter image description here

Upvotes: 0

Views: 1328

Answers (1)

Dan Shelly
Dan Shelly

Reputation: 6011

Request entity should be Question
[NSPredicate predicateWithFormat:SUBQUERY(comments,$comment,$comment.user.usr_id == %@).@count != 0",userId]

Upvotes: 2

Related Questions