title: Core Data : Insertion into One to Many Relationship
body: <p>I have just started learning how to implement Core Data Model on the iOS. After some basic tutorials on how to store and retrieve data with one to one relationship among entities, I am now trying to implement a one to many relationship. My data model consists of two entities with their respective classes defined as follows:</p>
  
  <pre><code>Restaurant:
  @interface Restaurant :NSObject
  @property (nonatomic, strong) NSString *name;
  @property (nonatomic, strong) NSMutableArray *user_reviews;   /* One to Many Relation to Review Entity*/
  @end
  
  Review:
  @interface Review : NSObject
  @property (nonatomic, strong) NSString *rating;
  @property (nonatomic, strong) NSString *review_text;
  @property (nonatomic, strong) User *user;
  @end
  </code></pre>
  
  <p>I found similar questions that used NSMutableSet to insert, but I am unable to implement the same for an NSMutable Array.</p>
  
  <p>Currently my insertion code looks like :</p>
  
  <pre><code>NSManagedObjectContext *context = [self managedObjectContext];
  Restaurant *rest = [NSEntityDescription insertNewObjectForEntityForName:@"Restaurant" inManagedObjectContext:context];
  rest.name = restaurant.name;
  </code></pre>
  
  <p>I retrieve the data for Restaurant and its Reviews via JSON and store them in temporary classes before saving them to the CORE Database.
  How do I insert such data which has One to Many Relationship ?</p>
  
  <p>EDIT :
  Currently I receive the data in the form of a class which defines the user_review property as </p>
  
  <pre><code>NSMutableArray *user_reviews;
  </code></pre>
  
  <p>I am trying to implement this same class to insert into core data model.
  But the core data model uses NSSet instead of NSMutableArray.
  One brute approach is to duplicate all the classes with the same properties except instead of using NSMutableArray, i change it to NSSet.
  But this creates a huge amount of redundant code. Shouldn't there be a more efficient way to do this ?</p>