javascript - Sails ReferenceError: Article "Model" is not defined -


i try access findone() through article model in controller, without success.

i had error

>  error: sending 500 ("server error") response:  >      referenceerror: article not defined >         @ object.module.exports.createarticle (c:\users\pisix\bizbiz\bizbizbackend\api\controllers\articlecontroller.js:16:9) >         @ bound (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\lodash\dist\lodash.js:729:21) >         @ routetargetfnwrapper (c:\users\pisix\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) >         @ callbacks (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) >         @ param (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) >         @ param (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) >         @ pass (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) >         @ nextroute (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:100:7) >         @ callbacks (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:167:11) >         @ c:\users\pisix\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:187:7 >         @ alwaysallow (c:\users\pisix\appdata\roaming\npm\node_modules\sails\lib\hooks\policies\index.js:207:11) >         @ routetargetfnwrapper (c:\users\pisix\appdata\roaming\npm\node_modules\sails\lib\router\bind.js:179:5) >         @ callbacks (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:164:37) >         @ param (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:138:11) >         @ param (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:135:11) >         @ pass (c:\users\pisix\appdata\roaming\npm\node_modules\sails\node_modules\express\lib\router\index.js:145:5) > [referenceerror: article not defined] 

how can fix it?

below article model

/** * article.js * * @description :: todo: might write short summary of how model works , represents here. * @docs        :: http://sailsjs.org/#!documentation/models */  module.exports = {     autopk: false,     autocreatedat: false,     autoupdatedat: false,     tablename:'article',     identity:'article',     attributes: {         idarticle:{             type:'integer',             unique:true,             required:true,             columnname:'idarticle',             autoincrement:true,             primarykey:true         },         titre:{             type:'string',             required:true,             columnname:'titre',             index:true         },         details:{             type:'text',             required:true,             columnname:'details',             size:100         },         etat:{             type:'string',             columnname:'etat',             enum:['vendu','réservé'],             index:true         },          prix:{             type:'float',             columnname:'prix',             index:true,             required:true         },         dateajout:{             type:'datetime',             columnname:'dateajout',             index:true,             required:true         },      } }; 

below controller articlecontroller.js

module.exports = {      /**      * `articlecontroller.createarticle()`      */     createoarticle: function (req, res) {         var idarticle = req.body.idarticle;         console.log('idarticle edit: '+ idarticle);         article.findone({idarticle:idarticle}).exec(function (err, article) {             if (article) {                 console.log('article '+ idarticle + ' trouvé');                 var dataarticle = req.body.article;                 article.titre = dataarticle.titre;                 article.details = dataarticle.details;                 article.prix = dataarticle.prix;                 article.etat = dataarticle.etat;                 article.dateajout=new date();                  article.save(function (err, success) {                     if (success) {                         return res.send({articleupdate: true, article: article,success:true,message:req.__('message-success-creation')});                     }                     if (err) {                         return res.send({success: false, message:req.__('message-erreur-update')})                     }                 });             }             if (err)             {                 //create article             }          });     },  }; 

i'm using sails v0.11

you don't have define identity of model. sails.js use identity , assign global think.

simply remove following line of model

identity:'article', 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -