设置一对多关系核心数据和神奇记录 [英] Setting one-to-many relationship Core Data and Magical Record

查看:176
本文介绍了设置一对多关系核心数据和神奇记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个对话消息具有一对多关系的实体(即一个对话可以有很多消息),我创建一个新的消息实体,如下:

If I have a Conversation entity with a one-to-many relationship to Messages (i.e. one conversation can have many messages) and I create a new message entity like so:

_message = [Message MR_createInContext:_managedObjectContext];
_message set properties ...

// Use this method to set relationship?
[_conversation addToMessageObject:(Message *)] 



如果我已经有一个_conversation对象,

If I already have a _conversation object, how do I add this new message to the conversation (in other words, how do I establish the relationship)?

推荐答案

我将这个新消息添加到会话中(换句话说,如何建立关系) ve还有一个问题,你需要在 _message 上创建关系:

I've had a problem with this too, you need to create the relationship on the _message instead:

_message.conversation = _conversation;

这篇关于设置一对多关系核心数据和神奇记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆