0

Im trying to send a response without certain fields, and RestKit still keeps setting the values to nil even after i have disabled this option using:

infoMapping.assignsDefaultValueForMissingAttributes = NO;

Full mapping code:

RKEntityMapping *infoMapping = [RKEntityMapping mappingForEntityForName:@"IndexInfo" inManagedObjectStore:managedObjectStore];
    //userMapping.identificationAttributes = @[@"id"];
    [infoMapping addAttributeMappingsFromDictionary:@{
                                                      @"first" : @"first",
                                                      @"last" : @"last"
                                                      }];

    infoMapping.assignsDefaultValueForMissingAttributes = NO;

RKResponseDescriptor *infoResponseDescriptor =
    [RKResponseDescriptor responseDescriptorWithMapping:infoMapping
                                                 method:RKRequestMethodGET
                                            pathPattern:@"/core/feed.json"
                                                keyPath:@"info"
                                            statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)

I really need to be able to respond with partial data, if this is a bug is there another way around it to hook the mapping to disable it manually?

nicwhitts
  • 190
  • 1
  • 3
  • 22

1 Answers1

0

It turns out that it was creating new entity's each time for my infoMapping.

So a workaround iv included an id attribute to the response, mapped this addition and used it as the identificationAttribute. This probably isn't the best solution but it works for now. (So my id is always 0 in my response)

I also included some validations within my IndexInfo model.

infoMapping.identificationAttributes = @[@"id"];
    [infoMapping addAttributeMappingsFromDictionary:@{
                                                      @"id" : @"id",
                                                      @"first" : @"first",
                                                      @"last" : @"last"
                                                      }];

validation:

- (BOOL)validateFirst:(id *)ioValue error:(NSError **)outError { ....

I also needed:

infoMapping.performsKeyValueValidation = YES;
infoMapping.discardsInvalidObjectsOnInsert = YES;

Instead of

//    infoMapping.assignsDefaultValueForMissingAttributes = NO;

The id is not ever used so I'l figure out a more elegant way and update answer.

nicwhitts
  • 190
  • 1
  • 3
  • 22