【问题标题】:Loopback: Cannot call Notification.create(). The create method has not been setup. The PersistedModel has not been correctly attached to a DataSource环回:无法调用 Notification.create()。尚未设置创建方法。 PersistedModel 未正确附加到 DataSource
【发布时间】:2015-05-15 07:23:36
【问题描述】:

我正在使用 Loopback 和推送组件。调用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。在代码中,我试图创建一个通知。有什么问题?

【问题讨论】:

    标签: node.js push-notification loopbackjs strongloop


    【解决方案1】:

    我在尝试使用用户模型的登录功能时也遇到了同样的问题。 经过一个小时的打击和试用后,它得到了修复。

    答案: 我将 User 模型扩展为 MyUser 模型(此模型内部没有编码,只是用作包装器)和内部 Hotel.js(在我的例子中是一个业务类,我在访问酒店详细信息之前用来验证用户身份)创建了一个用于登录的 remoteMethod

    代码:

    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'}
            }
        );
    

    这行得通!

    【讨论】:

      【解决方案2】:

      这个很老了,但只是在这里放点东西。在没有看到您的设置的情况下,我的猜测是您使用的模型没有连接到任何数据源,或者没有正确写入。默认连接器在内存中,并且确实正确实现了此方法。检查您的server/model-config.json 文件并找到Notification 的条目并检查您拥有的数据源。

      【讨论】:

        猜你喜欢
        • 2019-02-06
        • 2016-10-25
        • 2020-12-25
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多