RSA
RSA

Reputation: 1449

How to set a model to a variable in loopback?

fallowing code returns list of models var models = app.models();

models.forEach(function(Model) {
 console.log(Model.modelName); 
});
User        
AccessToken
ACL
RoleMapping 
Role        
Registration
Assets

when I using fallowing code to use Registration or Asstes:

D:\apps\newapps\testapp\node_modules\loopback\lib\application.js:129
    assert(Model.prototype instanceof Model.registry.getModel('Model'),
                ^

TypeError: Cannot read property 'prototype' of undefined
    at Function.app.model (D:\apps\newapps\testapp\node_modules\loopback\lib\application.js:129:17)
    at Object.<anonymous> (D:\apps\newapps\testapp\server\server.js:38:5)
    at Module._compile (module.js:573:30)
    at Object.Module._extensions..js (module.js:584:10)
    at Module.load (module.js:507:32)
    at tryModuleLoad (module.js:470:12)
    at Function.Module._load (module.js:462:3)
    at Function.Module.runMain (module.js:609:10)
    at startup (bootstrap_node.js:158:16)
    at bootstrap_node.js:598:3

Upvotes: 1

Views: 332

Answers (2)

Shubham Batra
Shubham Batra

Reputation: 2375

User is the model name.

var user = app.models.User;

resetPassword is function name of the user model, which take two parameter new_pwd and token,

user.resetPassword({
          new_pwd: new_password,
          token
        }, (err, data) => {
          if (err || !data.status) {
            return err || data;
          } else {
            return data;
          } 
        });

Upvotes: 1

Parsaria
Parsaria

Reputation: 1089

I am not expert of loopback but try this code:

var Registration = app.models.Registration;
console.log(Registration);
app.model(Registration);

Upvotes: 2

Related Questions