doesn't handle class names different from entity names #252

Closed
bcyng opened this Issue Sep 12, 2012 · 2 comments

Comments

Projects
None yet
2 participants
@bcyng

bcyng commented Sep 12, 2012

Magical record doesn't handle class names for entities that are different from the entity names.
In xcode these can be set in the .xcdatamodel file under configurations->default. the class names for each entity are specified under the class column in the entities section.

I believe the offending class in the NSManagedObject+MagicalRecord.m file is:

  • (NSString *) MR_entityName;

For my purposes I did a quick (and totally unmaintainable) fix as all my entity class names are prefixed with "Managed". I'll paste the code here to help in understanding the problem, but a more flexible solution is needed that reads the entity class names from the .xcdatamodel file.

+ (NSString *) MR_entityName
{
    NSString *string = NSStringFromClass(self);
    if ([[string substringToIndex:(@"Managed".length)] isEqualToString:@"Managed"]) {
        string = [string substringFromIndex:(@"Managed".length)];
    }    return string;
}
@blackgold9

This comment has been minimized.

Show comment Hide comment
@blackgold9

blackgold9 Sep 12, 2012

Contributor

I looked into the metadata classes available, and it seems technically possible. However, it's the uncommon case, and your solution of overriding MR_entityName is perfect (especially if you used mogenerator, which i recommend, since it won't be overwritten when you re-generate classes). For simplicity sake however, I would recommend naming your entities the same as your class names.

Contributor

blackgold9 commented Sep 12, 2012

I looked into the metadata classes available, and it seems technically possible. However, it's the uncommon case, and your solution of overriding MR_entityName is perfect (especially if you used mogenerator, which i recommend, since it won't be overwritten when you re-generate classes). For simplicity sake however, I would recommend naming your entities the same as your class names.

@blackgold9 blackgold9 closed this Sep 12, 2012

@bcyng

This comment has been minimized.

Show comment Hide comment
@bcyng

bcyng Sep 12, 2012

should this really be closed?
i'd imagine that you'd want to keep this open (as its a valid issue related to standard xcode functionality), and prioritised down, rather than closing if we don't want to spend the effort fixing it straight away? (either I or someone else will get around to fixing it properly eventually).

bcyng commented Sep 12, 2012

should this really be closed?
i'd imagine that you'd want to keep this open (as its a valid issue related to standard xcode functionality), and prioritised down, rather than closing if we don't want to spend the effort fixing it straight away? (either I or someone else will get around to fixing it properly eventually).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment