I am working with Restkit in my app. I have a problem in mapping one to one relationship.
I have two entities Task and TaskNote. Previously there was one to many relationship between Task and TaskNote i.e one task can have many notes.
This code was working fine then
NSDictionary *taskNoteObjectMapping = @{
@"noteID" : @"noteID",
@"taskID" : @"taskID",
@"time_stamp" : @"time_stamp",
@"noteText" : @"noteText",
@"note_user_phone_no" : @"note_user_phone_no",
@"note_username" : @"note_username"
};
RKEntityMapping *taskNoteEntityMapping = [RKEntityMapping mappingForEntityForName:@"TaskNote" inManagedObjectStore:managedObjectStore];
[taskNoteEntityMapping addAttributeMappingsFromDictionary:taskNoteObjectMapping];
taskNoteEntityMapping.identificationAttributes = @[@"noteID"];
[taskEntityMapping addPropertyMapping:[RKRelationshipMapping relationshipMappingFromKeyPath:@"taskNote" toKeyPath:@"taskNote" withMapping:taskNoteEntityMapping]];
But due to some requirement i have to change one to many relationship to one to one between task and its note i.e. one task can have one note. After this change my mapping starts to fail. i.e. when i use NSLog to observe a Task relationship with its Note it turn out nil. and RestKit is logging this error
Failed transformation of value at keyPath 'taskNote' to representation of type 'TaskNote': Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 "Failed transformation of value '(
"<TaskNote: 0x17833a60> (entity: TaskNote; id: 0x17833aa0 <x-coredata:///TaskNote/t33EC8AB0-1E62-4041-8B91-4B57BC0474F74> ; data: {\n noteID = 113;\n noteText = \"Note from server\";\n \"note_user_phone_no\" = \"+923335729486\";\n \"note_username\" = Myself;\n task = nil;\n taskID = 248;\n \"time_stamp\" = 14130583;\n})"
)' to TaskNote: none of the 2 value transformers consulted were successful." UserInfo=0x166ba240 {detailedErrors=(
"Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3002 \"The given value is not already an instance of 'TaskNote'\" UserInfo=0x16628750 {NSLocalizedDescription=The given value is not already an instance of 'TaskNote'}",
"Error Domain=org.restkit.RKValueTransformers.ErrorDomain Code=3000 \"Expected an `inputValue` of type `NSNull`, but got a `__NSArrayM`.\" UserInfo=0x166ba1e0 {NSLocalizedDescription=Expected an `inputValue` of type `NSNull`, but got a `__NSArrayM`.}"
Please guide what am i doing wrong here. How to map one to on relationship. After changing model i have also generated new Subclasses of entities Task and TaskNote.
I can give more info if required.
Aucun commentaire:
Enregistrer un commentaire