Restkit在后续提取时获取空结果

时间:2013-05-19 08:29:03

标签: core-data restkit-0.20

我面临着一个非常奇怪的问题,我希望有人可以帮助我。

我正在使用带有CoreData设置的Restkit(0.20),并且我拥有responseDescriptor的所有属性/关系映射设置。这是正确设置的,因为当我第一次调用getObjectsAtPath:参数时,我得到了正确的结果,并且能够映射到正确的对象。

但是,在随后的getObjectsAtPath调用中,mappingResult由于某种原因产生空结果,即使我可以看到来自服务器的请求就好了,并且相同的结果JSON被发送回客户端。

有没有人见过这个问题??!?!!?

这是映射代码:

 RKEntityMapping *userMapping = [User getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *voteMapping = [Vote getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *commentMapping = [Comment getEntityMapping:objectManager.managedObjectStore];
 RKEntityMapping *challengeActivityMapping = [ChallengeActivity getEntityMapping:objectManager.managedObjectStore];

// all relationship mapping
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"user" toKeyPath:@"user" withMapping:userMapping]];
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"votes" toKeyPath:@"votes" withMapping:voteMapping]];;
[challengeActivityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"comments" toKeyPath:@"comments" withMapping:commentMapping]];    

RKResponseDescriptor *challengeActivityResponse = [RKResponseDescriptor responseDescriptorWithMapping:challengeActivityMapping pathPattern:[ChallengeActivity restApiPathPattern] keyPath:@"challenge_activity" statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];

[objectManager addResponseDescriptorsFromArray:[NSArray arrayWithObjects:challengeActivityResponse, userResponse, voteResponse, commentResponse, errorResponse, nil]];

以下是每个请求返回的JSON有效内容:

[{
  challenge_activity: {
    id: 1,
    comment: "completed this task on time!",
    image_url: null,
    created_at: "2013-05-15T00:12:21Z",
    user: {
      id: 1,
      name: "Kevin Liang",
      image_url: <some_image_url>
    },
    votes: [{
      id: 3,
      user: {
         id: 1,
         name: "Kevin Liang",
         image_url: <some_image_url>
      }
    }],
    comments: [{
      id: 1,
      text: "first comment!",
      user: {
         id: 1,
         name: "Kevin Liang",
         image_url: <some_image_url>
      }
    }]
  }
}]

以下是获取代码:

- (void) fetchResultsFromServerAsync
{
    [[WellifyObjectManager manager] getObjectsAtPath:[[ChallengeActivity restApiPathPattern] stringByReplacingOccurrencesOfString:@":challenge_id" withString:[NSString stringWithFormat:@"%d", 1]] parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
        self.challengeActivities = [mappingResult array];
        [self.tableView reloadData];
        NSLog(@"Loaded activities");
    } failure:^(RKObjectRequestOperation *operation, NSError *error) {
        NSLog(@"Hit error: %@", error);
    }];
}

这是restkit调试输出,它显示了在第一次获取时缓存的对象(在获取数据时有意义),而第二次获取没有产生任何内容,因此没有缓存(即使调用是向服务器发出的):

2013-05-19 17:41:12.844 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:154 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities'
2013-05-19 17:41:12.944 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:185 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities' (200 OK) [0.0999 s]
2013-05-19 17:41:12.946 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'ChallengeActivity' by attributes 'objectId'
2013-05-19 17:41:12.951 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'User' by attributes 'objectId'
2013-05-19 17:41:12.953 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'Vote' by attributes 'objectId'
2013-05-19 17:41:12.955 WellifyiPhone[16147:21503] I restkit.core_data:RKInMemoryManagedObjectCache.m:64 Caching instances of Entity 'Comment' by attributes 'objectId'
2013-05-19 17:41:12.961 WellifyiPhone[16147:1d903] Loaded activities
2013-05-19 17:41:14.717 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:154 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities'
2013-05-19 17:41:14.819 WellifyiPhone[16147:1d903] I restkit.network:RKHTTPRequestOperation.m:185 GET 'http://0.0.0.0:3000/challenges/1/challenge_activities' (200 OK) [0.1021 s]
2013-05-19 17:41:14.820 WellifyiPhone[16147:1d903] Loaded activities

就像我之前提到的,第一次调用fetchResultsFromServerAsync方法时,[mappingResult array]返回一个ChallengeActivity的NSManagedObject。但是,在后续调用中,数组是空的。

0 个答案:

没有答案
相关问题