RestKit identificationAttributes不适用于collectionIndex

时间:2015-06-03 18:58:36

标签: restkit restkit-0.20

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

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

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

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

1 个答案:

答案 0 :(得分: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];
    }];