Giter Site home page Giter Site logo

Comments (9)

raymondfeng avatar raymondfeng commented on July 2, 2024

DataModel extends from Model. Can you post the full stack trace?

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

Sure

assert.js:92
  throw new assert.AssertionError({
            ^
AssertionError: Model must be a descendant of loopback.Model
    at Function.app.model (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback/lib/application.js:144:5)
    at ip (/Users/oleksiistrutsynskyi/Documents/api/app.js:48:9)
    at Array.forEach (native)
    at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/app.js:46:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)

from loopback-boot.

raymondfeng avatar raymondfeng commented on July 2, 2024

I just enhanced the error message with strongloop/loopback@a28e5b5. Can you tell which model is offending?

If you can show me the complete code for your model, it will be helpful.

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

Now it says:

 AssertionError: undefined must be a descendant of loopback.Model

Thanks - will do investigation why it is undefined :(

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

I don't sure how to solve the issue... I have 2 files:

userIdentity.json

{
    "name": "userIdentity",
    "options": {
      "base": "UserIdentity",
      "relations": {
        "user": {
          "model": "user",
          "type": "belongsTo",
          "foreignKey": "userId"
        }
      }
    },
    "public": true
}

userIdentity.js

  var loopback = require('loopback');

  module.exports = function(userIdentity, UserIdentity) {
    userIdentity.prototype.test = function(duration, cb) {
      cb('test');
    };
  };

loopback.remoteMethod(userIdentity.test, {
    returns: {
        arg: 'test',
        type: 'object',
    },
    accepts: [
        {arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
    ],
    http: {verb: 'POST', path: '/test'}
});

and in my app.js

// Create an instance of PassportConfigurator with the app instance
var PassportConfigurator = require('loopback-component-passport').PassportConfigurator;
var passportConfigurator = new PassportConfigurator(app);

// Initialize passport
passportConfigurator.init();

boot(app, __dirname);

// Set up related models
passportConfigurator.setupModels({
  userModel: app.models.user,
  userIdentityModel: app.models.userIdentity,
  userCredentialModel: app.models.userCredential
});

// Configure passport strategies for third party auth providers
for(var s in config) {
  var c = config[s];
  c.session = c.session !== false;
  passportConfigurator.configureProvider(s, c);
}

And the issue: Until I decided to add/extend userIdentity.js - everything was fine. But I after I try to extend userIdentity..... to be honest I can't do it :(

I am getting following error

/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:9
loopback.remoteMethod(userIdentity.test, {
                      ^
ReferenceError: userIdentity is not defined
    at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:9:23)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:156:20
    at Array.forEach (native)
    at defineModels (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:141:23)

from loopback-boot.

raymondfeng avatar raymondfeng commented on July 2, 2024

In userIdentity.js, you should do something like:

var loopback = require('loopback');
var app = require('../app');
var userIdentity = app.models.userIdentity; 
userIdentity.prototype.test = function(duration, cb) {
  cb('test');
};

loopback.remoteMethod(userIdentity.test, {
    returns: {
        arg: 'test',
        type: 'object',
    },
    accepts: [
        {arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
    ],
    http: {verb: 'POST', path: '/test'}
});

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

Tried it and getting:

/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:4
userIdentity.prototype.test = function(duration, cb) {
            ^
TypeError: Cannot read property 'prototype' of undefined
    at Object.<anonymous> (/Users/oleksiistrutsynskyi/Documents/api/models/userIdentity.js:4:13)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at /Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:156:20
    at Array.forEach (native)
    at defineModels (/Users/oleksiistrutsynskyi/Documents/api/node_modules/loopback-boot/lib/executor.js:141:23)

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

Seems like at this step the model is not in app.models yet

from loopback-boot.

cajoy avatar cajoy commented on July 2, 2024

After debugging figured correct way to implement it:

  var loopback = require('loopback');

  module.exports = function(userIdentity) {
    userIdentity.test = function(duration, callback) {
      callback(null, 'test done');
    };

    loopback.remoteMethod(userIdentity.test, {
        returns: {
            arg: 'test',
            type: 'object',
        },
        accepts: [
            {arg: 'test', type: 'Object', required: true, description: 'test', http: {source: 'body'}}
        ],
        http: {verb: 'POST', path: '/test'}
    });
  };

from loopback-boot.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.