을 게시하는 중첩된 관리되는 개체를 만들 중복
-
21-12-2019 - |
문제
나는 몇 가지 어려움을 게시 NSManagedObject 중첩된 NSManagedObjects 와 을.내가 나타나는 것을 점점 중복에 대한 기록 sub-NSManagedObjects 삽입 CoreData 경우 게시물을 반환합니다.여기의 스냅샷을 모델로:
여기에는 JSON 으로 나는 게시물:
{
"actions": [],
"application": "Identify",
"createBy": "welcomed",
"createDt": "2014-04-11T16:26:15Z",
"description": null,
"externalId": null,
"groupId": "5",
"id": 0,
"images": [
{
"format": "JPEG",
"height": 200,
"id": 0,
"image": "/9j/4A..../Pv5n/9k=",
"status": "C",
"type": "MUGSHOT",
"width": 200
}
],
"locked": null,
"modifyBy": null,
"modifyDt": null,
"priv": null
}
여기에 JSON 에서 반환된 후 서비스 POST:
{
"actions": [],
"application": "Identify",
"createBy": "welcomed",
"createDt": 1397233575000,
"description": null,
"externalId": null,
"groupId": "5",
"id": 11,
"images": [
{
"captureDevice": null,
"createBy": null,
"createDt": null,
"format": "JPEG",
"height": 200,
"id": 11,
"image": "/9j/4AAQSkZJR.../Pv5n/9k=",
"recordId": 11,
"status": "C",
"type": "MUGSHOT",
"width": 200
}
],
"locked": false,
"modifyBy": null,
"modifyDt": null,
"priv": false
}
편집(난 이것은 중요하다):여기에 대한 맵핑 WTSImage 및 WTSRecord:
RKEntityMapping *recordMapping = [RKEntityMapping mappingForEntityForName:@"WTSRecord" inManagedObjectStore:self.managedObjectStore];
[recordMapping addAttributeMappingsFromDictionary:@{
@"id":@"dbId",
@"externalId":@"extId",
@"groupId":@"groupId",
@"application": @"application",
@"description": @"desc",
@"priv": @"priv",
@"locked": @"locked",
@"createBy": @"createBy",
@"createDt": @"createDt",
@"modifyBy": @"modifyBy",
@"modifyDt": @"modifyDt",
}];
recordMapping.identificationAttributes = @[@"dbId"];
//image mapping
RKEntityMapping *imageMapping = [RKEntityMapping mappingForEntityForName:@"WTSImage" inManagedObjectStore:self.managedObjectStore];
[imageMapping addAttributeMappingsFromDictionary:@{
@"id": @"dbId",
@"status": @"status",
@"type": @"type",
@"format": @"format",
@"width": @"width",
@"height": @"height",
@"image": @"base64Image"
}];
imageMapping.identificationAttributes = @[@"dbId"];
[recordMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"images" toKeyPath:@"images" withMapping:imageMapping]];
다음 코드는 어디서 내가 만들 NSManagedObjects 및 전화 [RKObjectManager postObject:path:parameters:success:failure:
:
WTSRecord *record = [NSEntityDescription insertNewObjectForEntityForName:@"WTSRecord" inManagedObjectContext:self.managedObjectContext];
record.createBy = @"welcomed";
record.createDt = [NSDate date];
record.application = kWTSApplicationIdentify;
record.groupId = @"5";
WTSImage *image = [NSEntityDescription insertNewObjectForEntityForName:@"WTSImage" inManagedObjectContext:self.managedObjectContext];
image.height = [NSNumber numberWithFloat:mugshot.size.height];
image.width = [NSNumber numberWithFloat:mugshot.size.width];
image.imageData = UIImageJPEGRepresentation(imageData, 1.0);
image.type = kWTSCaptureTypeMugshot;
image.format = kWTSCaptureFormatJpeg;
image.status = kWTSCaptureStatusCaptured;
image.record = record;
[record addImagesObject:image];
RKObjectManager *manager = [RKObjectManager sharedManager];
[manager postObject:record path:@"records" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error Sending Record" message:error.localizedDescription delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}];
을 때 성공 블록 호출을 확인하 sqlite 데이터베이스 및 1WTSRecord 삽입 2 WTSImages.중 하나 WTSImages 올바른 FK 을 WTSRecord 및 PK 데이터베이스에서,다른 하나는 동안 나타나 분리된(자세한 내용 및 FK 을 WTSRecord 는 설정되지 않음).
여기에 대한 링크 을 핵심 데이터 추적 로그: https://dl.dropboxusercontent.com/u/466390/restkit2.txt
희망은 누군가가 도움이 될 수 있습니다!감사합니다!
편집 후에는 일부를,이 페이지: https://github.com/RestKit/RestKit/issues/1228
나를 만들어야 식별 요소가 클라이언트 측에서 사용하는 표에 게시하기 전에 휴식 서비스입니까?것 을 할 수 없을 지도 요청을 개시하는 개체들에서 이미 만들어진 객체 저장소 없이 먼저 설정을 식별 특성에 클라이언트 측?
해결책
대체 을 이해하는 어떻게 업데이트 항목은 응답 데이터,하지만 그는 적용되지 않는 관계 내용입니다.기술적으로 코딩될 수 있습니다,하지만 현재 사용하지 않.
필요할 경우 객체 관계에서 후에 매핑하는 동일한 개체를 만들때 문제가 있다.지 않는 경우에 그것을 마음는 다른 객체는 다음의 문제는 단지를 삭제합 복제...
중복 삭제:
가 요청 블록을 사용되지 않습니다 처리하는 경우 게시물 반응 그래서 당신이를 가져올 필요가 없기 때문에 속하고 삭제할 수 있습니다.나는 가정으로 모든 이미지 없음 관계를 기록하는 속도는 상대적으로 간단한 가를 실행할 수 있습니다.