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