Post中的Strongloop iOS LBUser扩展错误422

时间:2014-10-14 12:16:22

标签: objective-c json node.js digital-ocean strongloop

我正在尝试使用以下代码创建并将LBUser的用户扩展保存到服务器:

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是LBUserRepository扩展。显然用户的创建是可以的,但是当我尝试保存用户时,我收到了这个错误:

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.

似乎我名为Teacher的LBUser Extension无效且电子邮件和密码为空,但根据NSLog,它们不是空白。这是Teacher.h:

#import <Foundation/Foundation.h>
#import <LoopBack/LoopBack.h>

@interface Teacher : LBUser

@property (strong,nonatomic) NSString *bigarea;

@end

回到服务器我有一个.json描述老师:

{
  "name": "Teacher",
  "plural": "Teachers",
  "base": "User",
  "properties": {
    "bigarea": {
      "type": "string",
      "required": true
    }
  },
  "validations": [],
  "relations": {
    "courses": {
      "type": "hasMany",
      "model": "Course",
      "foreignKey": "courseId"
    }
  },
  "acls": [],
  "methods": []
}

对于如何代表目标C中的关系,我有点困惑。有人能给我一个亮点吗?

0 个答案:

没有答案