I'm trying to create and save a user extension of LBUser to the server with this code:
LBRESTAdapter *adapter = ((AppDelegate *)[[UIApplication sharedApplication] delegate]).adapter;
if (adapter) {
TeacherRepository *repo = (TeacherRepository *)[adapter repositoryWithClass:[TeacherRepository class]];
if (repo) {
Teacher *st = (Teacher *)[repo createUserWithEmail:@"test@test.com" password:@"test"];
st.bigarea = @"Mathematics";
NSLog(@"Email: %@", st.email);
NSLog(@"Password: %@", st.password);
if (st) {
[st saveWithSuccess:^{
NSLog(@"Saved in server!");
} failure:^(NSError *error) {
NSLog(@"Error: %@", error);
}];
}
}
}
TeacherRepository is a LBUserRepository extension. Apparently the creation of the user is ok, but when I try to save the user I get this error:
Error Domain=AFNetworkingErrorDomain Code=-1011 "Expected status code in (200-299), got 422" UserInfo=0x7f9418f07db0 {NSLocalizedRecoverySuggestion={"error":{"name":"ValidationError","status":422,"message":"The `Teacher` instance is not valid. Details: `password` can't be blank; `email` can't be blank; `email` is blank.","statusCode":422,"details":{"context":"Teacher","codes":{"password":["presence"],"email":["presence","format.blank"]},"messages":{"password":["can't be blank"],"email":["can't be blank","is blank"]}},"stack":"ValidationError: The `Teacher` instance is not valid. Details: `password` can't be blank; `email` can't be blank; `email` is blank.
It seems that my LBUser Extension named Teacher isn't valid and that email and password are blank, but according to the NSLog they are not blank. Here's the Teacher.h:
#import <Foundation/Foundation.h>
#import <LoopBack/LoopBack.h>
@interface Teacher : LBUser
@property (strong,nonatomic) NSString *bigarea;
@end
back at the server I have a .json describing teacher as this:
{
"name": "Teacher",
"plural": "Teachers",
"base": "User",
"properties": {
"bigarea": {
"type": "string",
"required": true
}
},
"validations": [],
"relations": {
"courses": {
"type": "hasMany",
"model": "Course",
"foreignKey": "courseId"
}
},
"acls": [],
"methods": []
}
Also I'm a little confused as to how represent the relations in Objective C. Can someone give me a light?