title: RestKit KVC Validation won't call validation methods
body: <p>this is my first question here :)</p>
  
  <p>OK so I have a projet with ReskKit 0.23.3 via cocoapods. I use RestKit/CoreData.</p>
  
  <p>I fetch an URL, the result got mapped to my object and is correctly saved by core data. I want to use Key-Value Validation to check some values retrieved against the one already persisted. I read that i could use the methods <code>validateKey:error:</code> on my <code>NSManagedObject</code>. Somehow, it is never called. I'm frustrated...</p>
  
  <p>Here are my files (for simplicity, i concatenated logic code into one flat file here):</p>
  
  <p><strong>JSON response /collections/{id}</strong></p>
  
  <pre><code>{
      "id": "00000000-0000-0000-0000-00000000000",
      "image_url": "http://server/image.png",
      "name": "Collection C",
      "etag": 42,
      "ctag": 42
  }
  </code></pre>
  
  <p><strong>Collection.h</strong></p>
  
  <pre class="lang-c prettyprint-override"><code>@interface Collection : NSManagedObject
  
  @property(nonatomic, strong) NSString *collectionId;
  @property(nonatomic, strong) NSString *name;
  @property(nonatomic, strong) NSURL *imageUrl;
  @property(nonatomic, strong) NSNumber *etag;
  @property(nonatomic, strong) NSNumber *ctag;
  
  @end
  </code></pre>
  
  <p><strong>Collection.m</strong></p>
  
  <pre class="lang-c prettyprint-override"><code>@implementation Collection
  
  @dynamic collectionId, name, imageUrl, etag, ctag;
  
  - (BOOL)validateCollectionId:(id *)ioValue error:(NSError **)outError {
      NSLog(@"Validating id");
      NSLog(@"Coredata collection id: %@", self.collectionId);
      NSLog(@"GET collection id: %@", (NSString *)*ioValue);
      return YES;
  }
  
  - (BOOL)validateEtag:(id *)ioValue error:(NSError **)outError {
      NSLog(@"Validating etag");
      NSLog(@"Coredata collection etag: %@", self.etag);
      NSLog(@"GET collection etag: %@", (NSString *)*ioValue);
      return YES;
  }
  
  @end
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre class="lang-c prettyprint-override"><code>NSManagedObjectModel *managedObjectModel = [NSManagedObjectModel mergedModelFromBundles:nil];
  RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
  
  [managedObjectStore createPersistentStoreCoordinator];
  NSString *storePath = [RKApplicationDataDirectory() stringByAppendingString:@"/MyApp.sqlite"];
  NSError *error;
  NSPersistentStore *persistentStore = [managedObjectStore addSQLitePersistentStoreAtPath:storePath fromSeedDatabaseAtPath:nil withConfiguration:nil options:nil error:&amp;error];
  NSAssert(persistentStore, @"Failed to add persistent store with error: %@", error);
  
  [managedObjectStore createManagedObjectContexts];
  
  managedObjectStore.managedObjectCache = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
  
  [RKManagedObjectStore setDefaultStore:managedObjectStore];
  
  NSURL *url = [NSURL URLWithString:@"http://server/api"];
  
  RKObjectManager *objectManager  = [self managerWithBaseURL:url];
  objectManager.requestSerializationMIMEType = RKMIMETypeJSON;
  objectManager.managedObjectStore = [RKManagedObjectStore defaultStore];
  
  RKEntityMapping *collectionMapping = [RKEntityMapping mappingForEntityForName:@"Collection" inManagedObjectStore:[RKManagedObjectStore defaultStore]];
  [collectionMapping addAttributeMappingsFromDictionary:@{@"id": @"collectionId",
                                                          @"image_url": @"imageUrl"}];
  [collectionMapping addAttributeMappingsFromArray:@[@"name", @"etag", @"ctag"]];
  [collectionMapping setIdentificationAttributes:@[@"collectionId"]];
  
  RKResponseDescriptor *collectionResponseDescriptors = [RKResponseDescriptor responseDescriptorWithMapping:collectionMapping
                                                                                                     method:RKRequestMethodGET pathPattern:@"collections/:collectionId"
                                                                                                    keyPath:nil
                                                                                                statusCodes:RKStatusCodeIndexSetForClass(RKStatusCodeClassSuccessful)];
  [objectManager addResponseDescriptor:collectionResponseDescriptor];
  
  [objectManager getObjectsAtPath:@"collections/00000000-0000-0000-0000-00000000000" parameters:nil success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult) {
      Collection *collection = (Collection *)[mappingResult.array firstObject];
      NSLog(@"Collection: %@", collection);
  } failure:^(RKObjectRequestOperation *operation, NSError *error) {
      NSLog(@"Oh noes :(");
  }];
  </code></pre>
  
  <p><strong>Output</strong></p>
  
  <pre><code>2014-09-13 12:39:04.242 MyApp[41958:607] I restkit:RKLog.m:33 RestKit logging initialized...
  2014-09-13 12:39:05.028 MyApp[41890:607] Collection: &lt;NSManagedObject: 0x9108a60&gt; (entity: Collection; id: 0x94166d0 &lt;x-coredata://6645F428-7631-45F0-A8AF-E2352C50F35E/Collection/p1&gt; ; data: {
      collectionId = "00000000-0000-0000-0000-00000000000";
      ctag = 42;
      etag = 42;
      imageUrl = "http://server/image.png";
      name = "Collection C";
  })
  </code></pre>
  
  <p>So, I get my Log with the Collection, but None of the NSLog in the <code>validate&lt;Key&gt;:error:</code> methods got triggered... Could not figure out why!</p>
  
  <p><strong>Edit</strong></p>
  
  <p>With some breaks, i figured this is RKMappingOperation who is responsible for calling those validation methods on my object. Precisely it's <code>validateValue:atKeyPath:</code></p>
  
  <p>RKMappingOperation.m</p>
  
  <pre class="lang-c prettyprint-override"><code>...
  - (BOOL)validateValue:(id *)value atKeyPath:(NSString *)keyPath
  {
      BOOL success = YES;
  
      if (self.objectMapping.performsKeyValueValidation &amp;&amp; [self.destinationObject respondsToSelector:@selector(validateValue:forKeyPath:error:)]) {
          NSError *validationError;
          success = [self.destinationObject validateValue:value forKeyPath:keyPath error:&amp;validationError];
          ...
      }
  ...
  </code></pre>
  
  <p>But <code>self.destinationObject</code> is an <code>NSManagedObject</code> and not a <code>Collection</code> object...</p>
  
  <p><strong>Console</strong></p>
  
  <pre><code>(lldb) po [self.destinationObject class]
  NSManagedObject
  </code></pre>
  
  <p>I hope you could lead me to the right way :) Thank you!</p>