balderdashy / sails

Realtime MVC Framework for Node.js
https://sailsjs.com
MIT License
22.82k stars 1.95k forks source link

TypeError: model.native is not a function #7143

Open coaperator opened 3 years ago

coaperator commented 3 years ago

Node version: 12 Sails version (sails): - ORM hook version (sails-hook-orm): - Sockets hook version (sails-hook-sockets): - Organics hook version (sails-hook-organics): - Grunt hook version (sails-hook-grunt): - Uploads hook version (sails-hook-uploads): - DB adapter & version (e.g. sails-mysql@5.55.5): sails-mongo, last version Skipper adapter & version (e.g. skipper-s3@5.55.5): -


Hi i am using express + waterline + mongodb trying to call a native method on a model but it gives me an error I don't understand how to fix it any ideas would be helpful

TypeError: model.native is not a function
      at D:\WebProjects\ides\back\services\NativeQuery.js:4:22
      at new Promise (<anonymous>)
      at Object.find (D:\WebProjects\ides\back\services\NativeQuery.js:3:12)
      at newConstructor.validateList (D:\WebProjects\ides\back\models\Accounts.js:581:41)
      at list (D:\WebProjects\ides\back\controllers\AccountsController.js:55:65)
      at Layer.handle [as handle_request] (D:\WebProjects\ides\back\node_modules\express\lib\router\layer.js:95:5)      
      at next (D:\WebProjects\ides\back\node_modules\express\lib\router\route.js:137:13)
      at Route.dispatch (D:\WebProjects\ides\back\node_modules\express\lib\router\route.js:112:3)
      at Layer.handle [as handle_request] (D:\WebProjects\ides\back\node_modules\express\lib\router\layer.js:95:5)      
      at D:\WebProjects\ides\back\node_modules\express\lib\router\index.js:281:22
      at param (D:\WebProjects\ides\back\node_modules\express\lib\router\index.js:354:14)
      at param (D:\WebProjects\ides\back\node_modules\express\lib\router\index.js:365:14)
      at Function.process_params (D:\WebProjects\ides\back\node_modules\express\lib\router\index.js:410:3)
      at next (D:\WebProjects\ides\back\node_modules\express\lib\router\index.js:275:10)
      at SendStream.error (D:\WebProjects\ides\back\node_modules\serve-static\index.js:121:7)
      at SendStream.emit (events.js:315:20)
sailsbot commented 3 years ago

@coaperator Thanks for posting! We'll take a look as soon as possible.

In the mean time, there are a few ways you can help speed things along:

Please remember: never post in a public forum if you believe you've found a genuine security vulnerability. Instead, disclose it responsibly.

For help with questions about Sails, click here.

eashaw commented 3 years ago

Hi @coaperator, would you mind sharing an example of how you're trying to call the native method in your code?

coaperator commented 3 years ago

Hi @coaperator, would you mind sharing an example of how you're trying to call the native method in your code?

Hi @eashaw, I made middleware, a model instance is passed to it

module.exports = {
  find: (model, query) => {
    return new Promise((resolve, reject) => {
      return model.native((err, collection) => {
        if (err) return reject(err);

        return collection.find(query).toArray((err, result) => {
          if (err) return reject(err);
          return resolve(result);
        });
      });
    });
  }
};
eashaw commented 2 years ago

Hi @coaperator, Would you be able to create a github repo of a minimal sails app that reproduces the issue you're having?