title: Core Data adding a new NSManagedObject
body: <p>I have my Core Data set up as such: </p>
  
  <p><code>SALES_REP</code> &lt;--->> <code>CUSTOMER</code> &lt;---->> <code>PURCHASE_AGREEMENT</code> &lt;&lt;------->> <code>PRODUCTS</code></p>
  
  <p>In the app, the sales rep can change the attributes of the <code>PRODUCTS</code> entity and this triggers changes to the <code>PURCHASE_AGREEMENT</code>. When they are finished editing the working <code>PA</code>, they can either submit via a web service to our CRM (SAP) or save their work locally.</p>
  
  <p>I understand (at least I think I do : D) how to create a new <code>NSManagedObject</code> and add values to it's attributes:</p>
  
  <pre><code>NSManagedObject* newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"PA" inManagedObjectContext:self.moc];
  
  //get the entity descriptions for PA, Customer, PA_Products and Sales_Rep
  NSEntityDescription* PAEntity = [NSEntityDescription entityForName:@"PA" inManagedObjectContext:self.moc];
  NSDictionary* dictPAAttributes = [PAEntity attributesByName];
  NSArray* arrPAAttributeNames = [dictPAAttributes allKeys];
  
  for(NSString* strThisAttribute in arrPAAttributeNames) {
      [newManagedObject setValue:[self.workingPA valueForKey:strThisAttribute] forKey:strThisAttribute];
  }
  </code></pre>
  
  <p>How would I go about adding the relationships? Do I have to fetch the newly created <code>PA</code> entity and then pull for the products, pull the <code>NSSet</code> of products from the workingPA and then add them to the new PA? And would the process be similar for the <code>CUSTOMER</code> and <code>SALES_REP</code> entities?</p>