Setting one-to-many relationship Core Data and Magical Record

爱⌒轻易说出口 提交于 2019-12-31 03:37:26

问题


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 *)] 

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)?


回答1:


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

_message.conversation = _conversation;


来源:https://stackoverflow.com/questions/22274428/setting-one-to-many-relationship-core-data-and-magical-record

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