聊天,对话,消息 - CoreData模型 [英] Chat, conversation, messaging - CoreData model
问题描述
在将问题标记为此问题的重复之前, a>请阅读说明。我不需要在评论中继续讨论。
所以我想为消息应用创建 CoreData
模型。像我在本主题中说的,我有三个实体:
-
用户$ c $
> -
对话
实体使用邮件定义对话用户。
好,所以我的数据模型是:
但是一切都在这里相互连接。上述答案与我的解决方案之间的唯一区别是 User
和 Message
- 多种关系。我想我需要,因为没有,这是不可能知道谁在对话中写了什么。
但是,就我所知道的数据模型,当一切都互相连接没有意义。
因此,这里的主要目标是:
- 在一个会话中可以加入至少两个用户
- 该消息仅支持短信
- 用户必须能够列出他的所有会话。
就是这样。
请验证当前解决方案,随时批评。
,实际上不需要 User
和 Conversation
之间的多对多关系。
/ p>
如果用户喜欢获取其所有对话,他可以使用此提取请求:
User * user = //获取一些用户你喜欢的对话
NSFetchRequest * r = [NSFetchRequest fetchRequestWithEntityName:@Conversation];
r.predicate = [NSPredicate predicateWithFormat:@ANY messages.author =%@,user];
以同样的方式,您可以获得给定会话的所有用户。
您可以将其建模为每个实体上的提取属性( User
和 code>)。
您应该考虑将聊天
关系更改为 messages
Before you mark a question as a duplicate of this question please read a description. I don't need to continue discussion there in the comment.
So I want to create CoreData
model for messaging app. Like said in this topic did i mentioned - i've had three entities:
User
entity define a author of message and participant in a conversation.Message
entity define every text sending with app.Conversation
entity defines conversation beetwen users using messages.
OK so my data model is like:
But everything is connected to each other here. The only difference between mentioned answer and my solution is that User
and a Message
are connected using one-to-many relationship. I think i need that, becouse without that it's impossible to know who wrote what in a conversation.
But as far as i know data model when everything is connected to each other have no sense.
So the key goals here is:
- In conversation screen i want to know who wrote what
- In one conversation can participate at least two users
- The message is text-only
- User have to be able to list all his conversations.
That's it.
Please validate the current solution and feel free to criticize.
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
这篇关于聊天,对话,消息 - CoreData模型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!