title: Relationships not Connected with Core Data and RestKit
body: <p>I've been working with RestKit (0.9.3) to populate some Core Data in my app. The entity objects are created correctly, but the relationships between them are not created. From what I can tell, I have things setup correctly according to:</p>
  
  <ol>
  <li><a href="https://github.com/RestKit/RestKit/wiki/Object-mapping" rel="nofollow">https://github.com/RestKit/RestKit/wiki/Object-mapping</a>  </li>
  <li>RKRelationshipMappingExample in the Examples folder</li>
  </ol>
  
  <p>So, here's a sample of the JSON that I'm getting back from the server:</p>
  
  <pre><code>{
    "artist" : {
      "artistId" : 123,
      "artistName" : "The Artist",
      "albums" : [
        {
          "albumPrice" : 12.99,
          "albumId" : 456,
          "trackCount" : 12,
          "albumName" : "Album Title",
        },
        {
          "albumPrice" : 10.99,
          "albumId" : 789,
          "trackCount" : 10,
          "albumName" : "Another Album Title",
        }
      ]
    }
  }
  </code></pre>
  
  <p>And I am using RestKit to populate the following two managed objects:</p>
  
  <pre><code>@interface Artist : NSManagedObject
  @property (nonatomic, retain) NSNumber * artistId;
  @property (nonatomic, retain) NSString * artistName;
  @property (nonatomic, retain) NSSet *albums;
  @end
  @interface Artist (CoreDataGeneratedAccessors)
  - (void)addAlbumsObject:(Album *)value;
  - (void)removeAlbumsObject:(Album *)value;
  - (void)addAlbums:(NSSet *)values;
  - (void)removeAlbums:(NSSet *)values;
  @end
  
  @interface Album : NSManagedObject
  @property (nonatomic, retain) NSNumber * albumId;
  @property (nonatomic, retain) NSString * albumName;
  @property (nonatomic, retain) NSNumber * albumPrice;
  @property (nonatomic, retain) NSNumber * trackCount;
  @property (nonatomic, retain) NSManagedObject *artist;
  @end
  </code></pre>
  
  <p>I've setup the following configurations with RestKit, and the intent is for 3 Core Data items to be created: one artist and two albums. The artist entity has a "albums" relationship which should be a set of these two albums.</p>
  
  <pre><code>// Initialize our RestKit singleton
  RKClient *client = [RKClient clientWithBaseURL:API_URL];  
  
  // Initialize for Object mapping
  RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:API_URL];
  objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"AppName.sqlite"];
  
  // Configure ALBUM mapping
  RKManagedObjectMapping* albumMapping = [RKManagedObjectMapping mappingForClass:[Album class]];
  albumMapping.primaryKeyAttribute = @"albumId";
  [albumMapping mapKeyPath:@"albumId" toAttribute:@"albumId"];
  [albumMapping mapKeyPath:@"albumName" toAttribute:@"albumName"];
  [albumMapping mapKeyPath:@"albumPrice" toAttribute:@"albumPrice"];
  [albumMapping mapKeyPath:@"trackCount" toAttribute:@"trackCount"];
  
  // Configure ARTIST mapping
  RKManagedObjectMapping* artistMapping = [RKManagedObjectMapping mappingForClass:[Artist class]];
  artistMapping.primaryKeyAttribute = @"artistId";
  [artistMapping mapKeyPath:@"artistId" toAttribute:@"artistId"];
  [artistMapping mapKeyPath:@"artistName" toAttribute:@"artistName"];    
  [artistMapping mapKeyPath:@"albums" toRelationship:@"albums" withMapping:albumMapping];
  
  // Register mappings with the provider
  [[RKObjectManager sharedManager].mappingProvider setMapping:albumMapping forKeyPath:@"albums"];
  [[RKObjectManager sharedManager].mappingProvider setMapping:artistMapping forKeyPath:@"artist"];
  </code></pre>
  
  <p>And then later in my program, I load the data:</p>
  
  <pre><code>RKObjectManager *objectManager = [RKObjectManager sharedManager];
  [objectManager loadObjectsAtResourcePath:@"/artist/123/albums" delegate:self];
  </code></pre>
  
  <p>After this is executed, my Core Data store is populated with the three objects (one artist and two albums), but the relationship between them is not created. </p>
  
  <p>The result is that I can fetch this list of albums directly, or I can fetch the artist directly. But if I try to use: <code>artist.albums</code> the result is empty.</p>
  
  <p>Can anyone offer suggestions on what I could be doing wrong, or how to further troubleshoot this?</p>
  
  <p>Thanks so much.</p>
  
  <p><strong>EDIT: Update 10/26</strong></p>
  
  <p>I just setup a small sample project with these same configurations and everything was loaded correctly (i.e. The artist entity was created with a relationship to it's albums). Sadly, this means that the issue is something in my larger project, rather than in what I outlined here earlier. With that said, I'll continue trudging though and updating, so if anyone has advice on how to troubleshoot this or where in particular to look, I would greatly appreciate it.</p>
  
  <p><strong>EDIT: Resolved</strong></p>
  
  <p>Embarrassingly, the problem was simply that I was using the wrong base url. I'll post full details (in case it can help anyone else) tomorrow.</p>