1

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.

Rost K.
  • 262
  • 2
  • 14

2 Answers2

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";
}
combinatorial
  • 9,132
  • 4
  • 40
  • 58
  • It happens when another user that have this group in relationship is logged in. When I make logout for all users that have the group everything is ok... Do you know why? – Rost K. Jul 22 '13 at 13:46
  • How is the inverse relationship between group and user defined? If in core data it is one-to-one then you can only have a single user associated with a single group. – combinatorial Jul 22 '13 at 16:12
  • User <<--> Group. Seems I can't change some Group object if some user have it in the relationship. When users are logged out everything is ok... So I can't add to group some user, or remove because the other user is logged in and keep it. – Rost K. Jul 23 '13 at 09:08
  • The fact is that this works generally, I have a very similar setup, so there must be something wrong with either your coredata config or your server schema. Is it the User <<-> Group relationship configured the same way on the server? If it is still not working I suggest you create a simple sample project and server and publish it to github so we can see your actual code. – combinatorial Jul 23 '13 at 14:05
  • One other thought... what are your permissions on the Group schema? Are Read and Update set to 'Open' – combinatorial Jul 23 '13 at 15:34
0

I found a solution: in my AppDelegate line "SM_CACHE_ENABLED = YES" make the crash...

Rost K.
  • 262
  • 2
  • 14