Note that there are some explanatory texts on larger screens.

plurals
  1. PORestKit 0.9.3 connectRelationship:withObjectForPrimaryKeyAttribute:
    primarykey
    data
    text
    <p>I am trying to use example RKCatalog from new RestKit 0.9.3. In RKRelationshipMappingExample creators have forgotten to add connection code between Task and User, but even after adding it doesn't work correctly.</p> <pre><code>{"project": { "id": 123, "name": "Produce RestKit Sample Code", "description": "We need more sample code!", "user": { "id": 1, "name": "Blake Watters", "email": "blake@twotoasters.com" }, "tasks": [ {"id": 1, "name": "Identify samples to write", "assigned_user_id": 1}, {"id": 2, "name": "Write the code", "assigned_user_id": 1}, {"id": 3, "name": "Push to Github", "assigned_user_id": 1}, {"id": 4, "name": "Update the mailing list", "assigned_user_id": 1} ] }} </code></pre> <hr> <pre><code>[taskMapping connectRelationship:@"assignedUser" withObjectForPrimaryKeyAttribute:@"assignedUserID"]; - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil { self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; if (self) { RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:gRKCatalogBaseURL]; objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:@"RKRelationshipMappingExample.sqlite"]; RKManagedObjectMapping* taskMapping = [RKManagedObjectMapping mappingForClass:[Task class]]; [taskMapping mapKeyPath:@"id" toAttribute:@"taskID"]; [taskMapping setPrimaryKeyAttribute:@"taskID"]; [taskMapping mapKeyPath:@"name" toAttribute:@"name"]; [taskMapping mapKeyPath:@"assigned_user_id" toAttribute:@"assignedUserID"]; [taskMapping connectRelationship:@"assignedUser" withObjectForPrimaryKeyAttribute:@"assignedUserID"]; [objectManager.mappingProvider setMapping:taskMapping forKeyPath:@"task"]; RKManagedObjectMapping* userMapping = [RKManagedObjectMapping mappingForClass:[User class]]; [userMapping mapAttributes:@"name", @"email", nil]; [userMapping mapKeyPath:@"id" toAttribute:@"userID"]; [userMapping setPrimaryKeyAttribute:@"userID"]; [userMapping mapRelationship:@"tasks" withMapping:taskMapping]; [objectManager.mappingProvider setMapping:userMapping forKeyPath:@"user"]; // NOTE - Project is not backed by Core Data RKObjectMapping* projectMapping = [RKObjectMapping mappingForClass:[Project class]]; [projectMapping mapKeyPath:@"id" toAttribute:@"projectID"]; [projectMapping mapAttributes:@"name", @"description", nil]; [projectMapping mapRelationship:@"user" withMapping:userMapping]; [projectMapping mapRelationship:@"tasks" withMapping:taskMapping]; [objectManager.mappingProvider setMapping:projectMapping forKeyPath:@"project"]; } return self; } </code></pre> <p>Am i doing everything alright? -- it doesn't connect task to user by user's ID.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload