问题
I have found a critical bug with relationships. I try to set relationship for my SMUserManagedObject after saving in the block "saveOnSuccess" and have a crash with a log:
* Terminating app due to uncaught exception 'SMExceptionIncompatibleObject', reason: 'No Attribute found for entity User which maps to the primary key on StackMob. The Attribute name should match one of the following formats: lowercasedEntityNameId or lowercasedEntityName_id. If the managed object subclass for User inherits from SMUserManagedObject, meaning it is intended to define user objects, you may return either of the above formats or whatever lowercase string with optional underscores matches the primary key field on StackMob.' It's looks like:
NSManagedObjectContext *context = [[[SMClient defaultClient] coreDataStore] contextForCurrentThread];
User *user = [[User alloc] initNewUserInContext:context];
[user setUsername:@"username1"];
[context saveOnSuccess:^{
user.group = group; //an already created object <--- Have a crash
} onFailure:^{
}];
After this my "Group" schema is spoiled. Any attempts is failure. If I try to set in any other place something like:
user.group = group; //Before using saveOnSuccess trick this line work perfectly!
I have a crash. Then I need to remove "Group" scheme at stackmob "Schema Configuration" for repair. So, I can't create an user object with presetted relationship.
回答1:
You can do one of two things...
Change your User class to inherit from SMUserManagedObject
. See the SMUserManagedObject section in the Stackmob Core Data Guide.
Or in the User class define a selector that returns the name of the primary key field:
- (NSString *)primaryKeyField
{
return @"username";
}
回答2:
I found a solution: in my AppDelegate line "SM_CACHE_ENABLED = YES" make the crash...
来源:https://stackoverflow.com/questions/17594149/ios-stackmob-sdk2-0-0-relationships-bug