0

I am using Loopback and the push component. When calling Notification.create() I get the error:

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

I'm just running the basic example server 2.0. In code I am trying to create a Notification. What's the problem?

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55
user798719
  • 9,619
  • 25
  • 84
  • 123

2 Answers2

1

I too got the same problem when trying to use login function of User model. Got it fixed after an hour of hit and trial.

Answer: I extended User model to MyUser model (No coding inside this model, just used it as a wrapper) and inside Hotel.js (in my case a business class where i use to authenticate user before accessing hotel details) created a remoteMethod for login

code:

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

This works!

Ashutosh Ranjan
  • 333
  • 2
  • 14
0

This one is pretty old, but just to put something up here. Without seeing your setup my guess is that the model you are using is not connected to any data source, or one that is not written properly. The default connector is in-memory and does implement this method correctly. Check your server/model-config.json file and find the entry for Notification and check what you have for the data source.

Jordan Kasper
  • 13,153
  • 3
  • 36
  • 55