RestKit/RestKit — Issue #506: Entity with class name different than entity name is not working in ActiveRecord
Author: krzak
Created: 2012-01-16 10:11:32+00:00
State: open

NSMAnagedObject+ActiveRecord have problems if entity use class that have different name than entity name. This is quick fix, but there is more methods in this class that relay on the assuption that entity name is exaclty the same as managed object class name.

+ (NSEntityDescription*)entity {
NSString* className = [NSString stringWithCString:class_getName([self class]) encoding:NSASCIIStringEncoding];
NSManagedObjectModel *model = [[RKObjectManager sharedManager].objectStore managedObjectModel];
for (NSEntityDescription *entity in model) {
if ([className isEqualToString:entity.managedObjectClassName]) {
return [NSEntityDescription entityForName:entity.name inManagedObjectContext:[self managedObjectContext]];
}
}

return [NSEntityDescription entityForName:className inManagedObjectContext:[self managedObjectContext]];
}