title: RestKit many-to-many mapping, how to?
body: <p>I'm working on my first RestKit app, and I use CoreData for local caching. In it I have a many-to-many relationship between Post &lt;&lt;--->> Category. The relationship is called posts, and categories. </p>
  
  <p>In my Post JSON call I get id's for the categories like this: <code>{"post": [...] "categories":[1,4] [...]</code>, where 1 and 4 is the ids. </p>
  
  <p>I have a custom <code>Post</code> model object that inherits from <code>NSManagedObject</code>, in it I have a property for categories, like this:</p>
  
  <pre><code>@interface Post : NSManagedObject
  
  [...]
  @property (nonatomic, retain) NSSet *categories;
  [...]
  </code></pre>
  
  <p>I do the same thing in a custom Category model object. </p>
  
  <p>My mappings currently looks like this:</p>
  
  <pre><code>RKManagedObjectMapping *categoryMapping = [RKManagedObjectMapping mappingForClass:[Category class] inManagedObjectStore:objectManager.objectStore];
  categoryMapping.primaryKeyAttribute = @"categoryId";
  categoryMapping.rootKeyPath = @"categories";
  [categoryMapping mapKeyPath:@"id" toAttribute:@"categoryId"];
  [categoryMapping mapKeyPath:@"name" toAttribute:@"name"];
  [...]
  
  
  RKManagedObjectMapping* postMapping = [RKManagedObjectMapping mappingForClass:[Post class] inManagedObjectStore:objectManager.objectStore];
  
  postMapping.primaryKeyAttribute = @"postId";
  postMapping.rootKeyPath = @"post";
  [postMapping mapKeyPath:@"id" toAttribute:@"postId"];
  [...]
  [postMapping mapKeyPath:@"created_at" toAttribute:@"createdAt"];
  [...]
  // Categories many-to-many.
  [postMapping mapKeyPath:@"categories" toRelationship:@"categories"  withMapping:categoryMapping];
  </code></pre>
  
  <p>When I run this I get the error: <code>'[&lt;__NSCFNumber 0x6c625e0&gt; valueForUndefinedKey:]: this class is not key value coding-compliant for the key id.'</code></p>
  
  <p>I would really appreciate if anyone could give me any clues on how to map this relationship. </p>