问题
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