Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Core data RestKit关系映射多对多核心数据关系错误_Core Data_Many To Many_Restkit - Fatal编程技术网

Core data RestKit关系映射多对多核心数据关系错误

Core data RestKit关系映射多对多核心数据关系错误,core-data,many-to-many,restkit,Core Data,Many To Many,Restkit,我使用RestKit将以下JSON映射到核心数据 我在核心数据中建立了多对多关系 一个料斗可以有多个用户,一个用户可以有多个料斗 我收到以下错误消息: (实体:料斗;id:0x767d240) 我的代码,遵循RestKit自述文件中的托管对象请求示例 我意识到需要更改参数的NSURL,但料斗似乎映射正常: `[managedObjectStore createManagedObjectContexts]; RKEntityMapping *userMapping = [RKEntityMa

我使用RestKit将以下JSON映射到核心数据

我在核心数据中建立了多对多关系

一个料斗可以有多个用户,一个用户可以有多个料斗

我收到以下错误消息:

(实体:料斗;id:0x767d240)

我的代码,遵循RestKit自述文件中的托管对象请求示例

我意识到需要更改参数的NSURL,但料斗似乎映射正常:

`[managedObjectStore createManagedObjectContexts];  
RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore];
[userMapping addAttributeMappingsFromDictionary:@{  @"avatar_url":          @"avatarURL"          ,
                                                      @"created_at":               @"createdAt",
                                                    @"link":                @"jsonURL",
                                                    @"post":                @"post",
                                                    @"thumbnail_url":       @"thumbnailURL",
                                                    @"updated_at":          @"updatedAt",
                                                    @"id":                  @"userID"}];
RKEntityMapping *hopperMapping = [RKEntityMapping mappingForEntityForName:@"Hopper"  inManagedObjectStore:managedObjectStore];
[hopperMapping addAttributeMappingsFromDictionary:@{   @"id":             @"hopperID",
                                                        @"lat":            @"lat",
                                                        @"lng":            @"lng",
                                                        @"name":           @"name",
                                                        @"created_at":     @"createdAt",
                                                        @"distance":        @"distance"}];

[hopperMapping addPropertyMapping:[RKRelationshipMapping     relationshipMappingFromKeyPath:@"hopperToUsers" toKeyPath:@"hopperToUsers" withMapping:userMapping]];

NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:hopperMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"hoppers" statusCodes:statusCodes];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000/hoppers.json?lat=30.422032&lng=-86.617069"]];
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
operation.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
operation.managedObjectCache = managedObjectStore.managedObjectCache;
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation,      RKMappingResult *result) {
    Hopper *hopper= [result firstObject];
    NSLog(@"Mapped the hopper: %@", hopper);
    NSLog(@"Mapped the user: %@", [hopper.hopperToUsers anyObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
NSOperationQueue *operationQueue = [NSOperationQueue new];
[operationQueue addOperation:operation];}`

当您调用
addPropertyMapping
并创建关系映射时,
..FromKeyPath
与JSON相关,因此它应该设置为
@“users”

,感谢您的快速回复。当我这样做时,它会说…实体Hopper与键“users”的键值编码不兼容.“那么关键路径应该是另一种方式,RestKit需要知道在JSON中从何处获取数据,以及将数据放在对象中的何处。噢,感谢对addProperty映射的澄清。我有fromKetPath:@“users”和toKeyPath:HopperToUsers(我在核心数据中的关系)…希望这是对的。现在我得到了关于URL的响应错误。所以这个问题已经解决了,我会看看当我修复NSURL时会发生什么。我会放弃你,但这是我的第一篇帖子!
{
    "hoppers": [{
        "bearing": 0,
        "created_at": "2013-07-26T07:57:00Z",
        "distance": 0.0,
        "id": 4,
        "lat": "30.422032",
        "lng": "-86.617069",
        "name": "Fort Walton Beach",
        "updated_at": "2013-07-26T07:57:00Z",
        "users": [{
            "avatar_url": null,
            "created_at": "2013-07-26T21:37:21Z",
            "id": 1,
            "link": "http:/example.com/savetheday",
            "name": "Clark Kent",
            "post": " I once reported a heinous crime here.   Superman came to the rescue!",
            "thumbnail_url": null,
            "updated_at": "2013-07-26T21:37:21Z"
        }, {
            "avatar_url": null,
            "created_at": "2013-07-26T21:37:57Z",
            "id": 2,
            "link": "http:/example.com/villaincaught",
            "name": "Lex Luther",
            "post": " I got busted here. Almost took over the world!",
            "thumbnail_url": null,
            "updated_at": "2013-07-26T21:37:57Z"
        }]
    }]
}
`[managedObjectStore createManagedObjectContexts];  
RKEntityMapping *userMapping = [RKEntityMapping mappingForEntityForName:@"User" inManagedObjectStore:managedObjectStore];
[userMapping addAttributeMappingsFromDictionary:@{  @"avatar_url":          @"avatarURL"          ,
                                                      @"created_at":               @"createdAt",
                                                    @"link":                @"jsonURL",
                                                    @"post":                @"post",
                                                    @"thumbnail_url":       @"thumbnailURL",
                                                    @"updated_at":          @"updatedAt",
                                                    @"id":                  @"userID"}];
RKEntityMapping *hopperMapping = [RKEntityMapping mappingForEntityForName:@"Hopper"  inManagedObjectStore:managedObjectStore];
[hopperMapping addAttributeMappingsFromDictionary:@{   @"id":             @"hopperID",
                                                        @"lat":            @"lat",
                                                        @"lng":            @"lng",
                                                        @"name":           @"name",
                                                        @"created_at":     @"createdAt",
                                                        @"distance":        @"distance"}];

[hopperMapping addPropertyMapping:[RKRelationshipMapping     relationshipMappingFromKeyPath:@"hopperToUsers" toKeyPath:@"hopperToUsers" withMapping:userMapping]];

NSIndexSet *statusCodes = RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful); // Anything in 2xx
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:hopperMapping method:RKRequestMethodAny pathPattern:nil keyPath:@"hoppers" statusCodes:statusCodes];

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:3000/hoppers.json?lat=30.422032&lng=-86.617069"]];
RKManagedObjectRequestOperation *operation = [[RKManagedObjectRequestOperation alloc] initWithRequest:request responseDescriptors:@[responseDescriptor]];
operation.managedObjectContext = managedObjectStore.mainQueueManagedObjectContext;
operation.managedObjectCache = managedObjectStore.managedObjectCache;
[operation setCompletionBlockWithSuccess:^(RKObjectRequestOperation *operation,      RKMappingResult *result) {
    Hopper *hopper= [result firstObject];
    NSLog(@"Mapped the hopper: %@", hopper);
    NSLog(@"Mapped the user: %@", [hopper.hopperToUsers anyObject]);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
    NSLog(@"Failed with error: %@", [error localizedDescription]);
}];
NSOperationQueue *operationQueue = [NSOperationQueue new];
[operationQueue addOperation:operation];}`