title: RestKit serialization of Core Data relationship
body: <p>I have a CoreData backed contact object that has a one-to-many relationship to both email and phone_number entities. All objects mentioned here are NSManagedObjects.</p>
  
  <p>The phone_number and email entity both just have one attribute which is an NSString* representing the phone_number and email respectively.</p>
  
  <p>Currently when I serialize the object I get something like</p>
  
  <pre><code>    {contacts: 
          [{"name":"person1", 
          "emails":[{"email":"email1@email.com"}, {"email":"email2@email.com"}], 
          "phone_numbers":[{"number":"1111111111"}, {"number":"2222222222"}]},
          {"name":"person2", 
          "emails":[{"email":"email1@email.com"}, {"email":"email2@email.com"}],
          "phone_numbers":[{"number":"3333333333"}, {"number":"4444444444"}]}]
      }
  </code></pre>
  
  <p>I would like to serialize to something like this</p>
  
  <pre><code>    {contacts: 
          [{"name":"person1", 
          "emails":["email1@email.com","email2@email.com"], 
          "phone_numbers":["1111111111", "2222222222"]},
          {"name":"person2", 
          "emails":["email1@email.com", "email2@email.com"],
          "phone_numbers":["3333333333", "4444444444"]}]
      }
  </code></pre>
  
  <p>notice how the list of "emails" and "phone_numbers" are just a list of strings, without an associated key for each phone_number/email</p>
  
  <p>my current mapping code is (the phone_number mapping code is exactly the same as the Email mapping code)</p>
  
  <pre><code>    @implementation Email
  
      @dynamic email;
      @dynamic contact;
  
      + (void)emailRKObjectMapping {
        RKManagedObjectMapping* emailMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Email" inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
        [emailMapping mapKeyPath:@"email" toAttribute:@"email"];
        [[RKObjectManager sharedManager].mappingProvider addObjectMapping:emailMapping];
  
        //Serialization mapping for Contact class
        [[RKObjectManager sharedManager].mappingProvider setSerializationMapping":[emailMapping inverseMapping] forClass:[Email class]];
       }
      @end
  </code></pre>
  
  <p>The Contact mapping code that has a relationship pointing to the Email/Phone Number</p>
  
  <pre><code>    @implementation Contact
      ...
      @dynamic emails;
      @dynamic phoneNumbers;
      ...
  
      + (void)contactRKObjectMapping {
        RKManagedObjectMapping* contactMapping = [RKManagedObjectMapping mappingForEntityWithName:@"Contact" inManagedObjectStore:[RKObjectManager sharedManager].objectStore];
  
        ...
        ...
  
        [[RKObjectManager sharedManager].mappingProvider addObjectMapping:contactMapping];
  
        //Serialization mapping for Contact class
        RKManagedObjectMapping* contactSerializationMapping = [contactMapping copy];
        [contactSerializationMapping mapKeyPath:@"emails" toRelationship:@"emails" withMapping:[[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[Email class]]];
        [contactSerializationMapping mapKeyPath:@"phone_numbers" toRelationship:@"phoneNumbers" withMapping:[[RKObjectManager sharedManager].mappingProvider objectMappingForClass:[PhoneNumber class]]];
        [[RKObjectManager sharedManager].mappingProvider setSerializationMapping:[contactSerializationMapping inverseMapping] forClass:[Contact class]];
      }
  </code></pre>
  
  <p>To me it seems silly to have to send the key "phone_number" or "email" up for every phone number and email in the array of emails and phone_numbers. I just want an easy way to serialize to an array of strings with one key.</p>
  
  <p>Thanks for your help!</p>