2015-06-03 15 views
0

我的用例是,对于特定的集合端点,我创建了一个本地Core-Data支持的联结表来指定顺序。这是一个抽象的对象;不是我可以直接映射的。RestKit identificationAttributes不能用于collectionIndex

我成功创建了集合,所有对象和所有订单的表示形式。在后续请求中,创建重复的订单对象。

我的identificationAttributes数组包含表示页面偏移量的属性和表示请求相对顺序的属性。 (查询参数基于偏差&限制。项目的顺序=偏移+相对顺序)。

在我看来,这是RestKit的一个问题(如果我删除了collectionIndex属性,则不会创建重复项,此外我已验证将正确的数值设置为此属性);但我是新手。 collectionIndex可以用作识别属性,还是不允许?

+0

注:我也尝试了人工识别属性按这个问题:https://github.com/RestKit/RestKit/issues/1604但它不工作为0.24.1;发生什么事情最终只有一个订单对象,并且每次新请求都会重复。可能这是因为在创建单个对象期间不会调用willSave? – michael

回答

0

我查看了RKMapperOperation,发现这个代码,它显示只有在识别属性被处理后才计算collectionIndex。没有改变RestKit,这是不可能的。方法objectForRepresentation:withMapping:检索现有对象,然后更改其索引。

[objectsToMap enumerateObjectsUsingBlock:^(id mappableObject, NSUInteger index, BOOL *stop) { 
     id destinationObject = [self objectForRepresentation:mappableObject withMapping:mapping]; 
     if (destinationObject) { 
      mappingData.collectionIndex = index; 
      BOOL success = [self mapRepresentation:mappableObject toObject:destinationObject isNew:YES atKeyPath:keyPath usingMapping:mapping metadataList:metadataList]; 
      if (success) [mappedObjects addObject:destinationObject]; 
     } 
     *stop = [self isCancelled]; 
    }];