can call function in model from controller with sails framework?

node.js, sails.js

Solution

What you're trying to do isn't an instance method. Instead of calling just `User.CallUserFunction()` you need to do something like this:

User Model

module.exports = {
  attributes: {
     name: {
       type: 'string',
       required: true
     }
  },
 CallUserFunction: function(){
   //some code goes here.
 }
}

User Controller

module.exports = {
   create: function(req, res){
      sails.models.user.CallUserFunction();//can i call function in user Model like this? 
  }
}

edit: forgive any typo's as i'm not in front of my dev workstation to test this, i do know its very close to that syntax of `sails.models` though.

Problem

I have user model and user Controller that I have generate from sails command. I just want call function that I created on model from controller like: // user model ``` module.exports = { attributes: { name: { type: 'string', required: true } }, CallUserFunction: function(){ //some code goes here. } } ``` // userController ``` module.exports = { create: function(req, res){ User.CallUserFunction();//can i call function in user Model like this? } } ```

Original source

Related problems