0
votes

Quick core data question.

I am trying to link core data objects in a many-to-many relationship:

  • Comments (has a property called commentHashTags)
  • Hashtags (has a property called hashTagComments)

In a one to many relationship I would get away doing:

  • commentObject.commentHashTag = hashTagObject

Is there a way to do something similar in a many-to-many relationship without having to create a class of core data objects in the middle (commentHashTagRelationship).

Looking forward to any help, I am very reluctant to update my core data model since it would force our existing users to re-install their clients.

1
Why do you need to create a class in the middle? Why not to-many relationship both ways (inverse of each other)?Rakesh

1 Answers

0
votes

Instead of using:

commentObject.commentHashTag = hashTagObject

when you are using to-many relationship, to add an object to the relationship it'll be something like:

NSMutableSet *tempRelationSet = commentObject.commentHashTags;
[tempRelationSet addObject:newHashTagObject];
commentObject.commentHashTags = tempRelationSet;