RestKit many-to-many with Core Data: it works, but am I doing it right?

I am new to RestKit. I am trying to map many-to-many relationships between Space and User objects. For the purposes of this question, suppose all Space objects are in the master data store correctly.

In the REST API, I can make one call to get all users for a given space. First of all, when I initialize my class to retrieve the network, I set up the mapping corresponding to parsing the list of users:

RKManagedObjectMapping *teamMapping = [RKManagedObjectMapping mappingForEntity:[NSEntityDescription entityForName:@"User" inManagedObjectContext:self.manager.objectStore.primaryManagedObjectContext] inManagedObjectStore:self.manager.objectStore];

[teamMapping mapKeyPath:@"id" toAttribute:@"userID"];
[teamMapping mapKeyPath:@"name" toAttribute:@"name"];
teamMapping.primaryKeyAttribute = @"userID";
[self.manager.mappingProvider setMapping:teamMapping forKeyPath:@"users.user"];

Then, to populate links for users in spaces, I do this:

NSArray *spaces = [self.managedObjectContext executeFetchRequest:[NSFetchRequest fetchRequestWithEntityName:@"Space"] error:nil];

for (QBSpace *space in spaces)
{
    [self.manager loadObjectsAtResourcePath:[NSString stringWithFormat:@"space/%@/users", space.wikiName] usingBlock:^(RKObjectLoader *loader) {
        loader.onDidLoadObjects = ^(NSArray *objects){
            space.team = nil;
            for (QBUser *user in objects)
            {
                [space addTeamObject:user];
            }

        };
    }];
}

That is, I manually add a space-> user link based on the returned array of objects.

? , , , , RestKit .

XML

<users type="array">
<user>
<id>aPrimaryKey</id>
<login>loginName</login>
<login_name warning="deprecated">loginName</login_name>
<name>Real Name</name>
</user>

, , , : URL, , , .

RestKit "--"?

+3
1

, ?

, ManagedObject Space. RKObjectLoaderDelegate.

, , loadAtResourcePath objectLoader:didLoadObject:(id)object objectLoader:didLoadObjectDictionary: .

Space , ?

, , . .:)

+1

All Articles