Chat, conversation, messaging - CoreData model

浪尽此生 提交于 2019-12-05 20:24:48

As far as I can tell, there is no real need for the many-to-many relationship between User and Conversation.

If a user like to get all of its conversations he could use this fetch request:

User* user = //get some user you like conversations for
NSFetchRequest* r = [NSFetchRequest fetchRequestWithEntityName:@"Conversation"];
r.predicate = [NSPredicate predicateWithFormat:@"ANY messages.author = %@",user];

In the same fashion you could get all users of a given conversation.

You could model this as a fetched property on each of these entities (User and Conversation).

You should really consider changing the chat relationship to messages

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!