Loopback:不能调用Notification.create().没有设置create方法.PersistedMod



我正在使用环回和推送组件。当调用Notification.create()时,我得到错误:

Cannot call Notification.create(). The create method has not been setup. 
The PersistedModel has not been correctly attached to a DataSource!

我只是运行基本示例服务器2.0。在代码我试图创建一个通知。有什么问题吗?

在尝试使用用户模型的登录功能时,我也遇到了同样的问题。经过一个小时的试验才修好。

答案:我将User模型扩展到MyUser模型(在此模型中没有编码,只是将其用作包装器),并在 hotel .js(在我的情况下,我使用业务类在访问酒店详细信息之前对用户进行身份验证)中创建了一个remotemmethod用于登录

代码:

Hotel.auth=function(uname,pwd, cb)
    {
        Hotel.app.models.MyUser.login({username: uname, password: pwd}, function (err, token) {
            if(err)
                cb(null,err);
            else
                cb(null,token);
        });
    }
    Hotel.remoteMethod(
        'auth', 
        {
           accepts: 
          [
          {arg: 'uname', type: 'string',required: true},
          {arg: 'pwd', type: 'string',required: true}
          ],
          returns: {arg: 'Response Message', type: 'string'}
        }
    );

这工作!

这个已经很老了,不过我还是想说一下。在没有看到您的设置的情况下,我猜测您正在使用的模型没有连接到任何数据源,或者没有正确编写的数据源。默认连接器位于内存中,并正确实现此方法。检查您的server/model-config.json文件,找到Notification条目,并检查您的数据源。

相关内容

最新更新