2015-06-03 62 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]; 
    }];