我對我的應用程序使用了RestKit 0.20.3。它具有離線模式,所以我必須將對象存儲在本地coredata中。RestKit本地刪除對象,仍然出現在映射中
每當從服務器刪除一些對象時,它會發送JSON中的deleted = true
屬性,我在與deletionPredicate
的映射中處理該屬性。 這是我的映射。
- (RKEntityMapping *)meetingsMapping {
RKEntityMapping *meetingsMapping = [RKEntityMapping mappingForEntityForName:@"DBMeetings" inManagedObjectStore:objectManager.managedObjectStore];
meetingsMapping.setDefaultValueForMissingAttributes = NO;
meetingsMapping.deletionPredicate = [NSPredicate predicateWithFormat:@"shouldBeDeleted = 1"];
[meetingsMapping setModificationAttributeForName:@"updated_at"];
meetingsMapping.identificationAttributes = @[@"id"];
[meetingsMapping addAttributeMappingsFromDictionary:@{
@"id": @"id",
@"title": @"title",
@"start_date_human": @"start_date_human",
@"start_time_human": @"start_time_human",
@"finish_date_human": @"finish_date_human",
@"finish_time_human": @"finish_time_human",
@"lock": @"lock",
@"location": @"location",
@"sample": @"sample",
@"deleted": @"shouldBeDeleted",
@"created_at": @"created_at",
@"updated_at": @"updated_at",
@"follow_up_id": @"follow_up_id",
@"total_topics": @"total_topics",
}];
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"tags" mapping:[self tagsMapping]];
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"required_participants" mapping:[self contactsMapping]];
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"optional_participants" mapping:[self contactsMapping]];
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"readonly_participants" mapping:[self contactsMapping]];
[meetingsMapping addRelationshipMappingWithSourceKeyPath:@"organizer" mapping:[self contactsMapping]];
return meetingsMapping;
}
它運作良好,並且屬性是從本地CoreData刪除。
問題是方法getObjectsAtPath
仍返回mappingResult
參數中的所有對象。
假設,如果5出的20個對象被刪除,mappingResult.array
返回20條記錄不15. 5個刪除的記錄沒有數據。當我登錄mappingResult.array
,第一條記錄打印如下:
2014-03-27 13:10:14.105 MeetingKing[7851:70b] W restkit.network.core_data:RKManagedObjectRequestOperation.m:125 Unable to refetch managed object <DBMeetings: 0xc1cb820> (entity: DBMeetings; id: 0xc1a6a60 <x-coredata://7B9FC7F6-C0E9-4DF5-91AC-D7C49F54B4F5/DBMeetings/t2915CF2E-2D7D-4E29-8B39-B1C51151809410> ; data: <fault>): the object has a temporary managed object ID.
2014-03-27 13:10:14.105 MeetingKing[7851:70b] W restkit.network.core_data:RKManagedObjectRequestOperation.m:125 Unable to refetch managed object <DBMeetings: 0xc5b2ed0> (entity: DBMeetings; id: 0xc5d1110 <x-coredata://7B9FC7F6-C0E9-4DF5-91AC-D7C49F54B4F5/DBMeetings/t2915CF2E-2D7D-4E29-8B39-B1C51151809416> ; data: <fault>): the object has a temporary managed object ID.
2014-03-27 13:10:14.106 MeetingKing[7851:70b] W restkit.network.core_data:RKManagedObjectRequestOperation.m:125 Unable to refetch managed object <DBMeetings: 0xc58b6a0> (entity: DBMeetings; id: 0xc5d3de0 <x-coredata://7B9FC7F6-C0E9-4DF5-91AC-D7C49F54B4F5/DBMeetings/t2915CF2E-2D7D-4E29-8B39-B1C51151809417> ; data: <fault>): the object has a temporary managed object ID.
2014-03-27 13:10:14.106 MeetingKing[7851:70b] W restkit.network.core_data:RKManagedObjectRequestOperation.m:125 Unable to refetch managed object <DBMeetings: 0xc5b50e0> (entity: DBMeetings; id: 0xc5d4af0 <x-coredata://7B9FC7F6-C0E9-4DF5-91AC-D7C49F54B4F5/DBMeetings/t2915CF2E-2D7D-4E29-8B39-B1C51151809419> ; data: <fault>): the object has a temporary managed object ID.
2014-03-27 13:10:14.107 MeetingKing[7851:70b] W restkit.network.core_data:RKManagedObjectRequestOperation.m:125 Unable to refetch managed object <DBMeetings: 0xc1ed5a0> (entity: DBMeetings; id: 0xc1c84e0 <x-coredata://7B9FC7F6-C0E9-4DF5-91AC-D7C49F54B4F5/DBMeetings/t2915CF2E-2D7D-4E29-8B39-B1C51151809422> ; data: <fault>): the object has a temporary managed object ID.
如果我在DB檢查,只有15條記錄。沒關係。
如果我明確地從數據庫提取,它只返回15條記錄,這是確定
但在getObjectsAtPath
回調,則mappingResult.array
參數返回20條記錄。這不好。 :(
的問題是mappingResult.array
count
變成20和我UITableView
顯示20行,5行沒有數據。
是否有任何其他的回調由RestKit準確返回15條記錄,所以我不會必須從數據庫中明確提取記錄?
謝謝@wain,我使用MagicalRecords,並將它用於從數據庫中再次提取。它正在返回正確的記錄。我想知道是否有其他方法可以實現這一目標。 – Khawar