magicalpanda / MagicalRecord

Super Awesome Easy Fetching for Core Data!
Other
10.8k stars 1.79k forks source link

Configuration entity to class mapping failed #1140

Open lolgear opened 8 years ago

lolgear commented 8 years ago

It seems that configuration mapping entity -> class is unused.

+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context
{
    NSString *entityName = [self MR_entityName];//[[self new] entity].name;
    return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}

Could be fixed as this:

+ (NSEntityDescription *) MR_entityDescriptionInContext:(NSManagedObjectContext *)context
{
    // hah, not so fast :)
    // it fails, of course
    NSString *entityName = [[self new] entity].name; // or some preparations for name like module dot separation.
    return [NSEntityDescription entityForName:entityName inManagedObjectContext:context];
}

See here:

+ (NSString *) MR_entityName;
{
    NSString *entityName;

    if ([self respondsToSelector:@selector(entityName)])
    {
        entityName = [self performSelector:@selector(entityName)];
    }

    if ([entityName length] == 0)
    {
        // Remove module prefix from Swift subclasses
        // entity name and entity class could be different!
        entityName = [NSStringFromClass(self) componentsSeparatedByString:@"."].lastObject;
    }

    return entityName;
}