node.js - How can I access my models in sailsjs outside a controller? -
i have controller looks this.
module.exports = { readbyslug: function (req, res) { var slug = req.param('id'); store.findonebyname(slug.split('-').join(' ')) .then(function(err, store){ if(err) res.send({status:'error', msg:'no store'}); res.send(store); }); } }; however, rather not have login in controllers, rather stick them in module.
my question is, how access models? global or something?
chadams-- models global default. if did sails generate model foo, access foo in code. if you'd rather not access them way, can use sails reference access sails.models.foo, same thing.
hope helps!
btw auto-globalization disable-able customizing
sails.config.globals. example:
// configure what's available globally, make new file, `config/globals.js` // following contents: // in example, i'll disable globalization of models, _ , async. // (but i'll leave `sails` global available.) // variables made globally accessible server process module.exports.globals = { _ : false, async: false, models: false, sails: true };
Comments
Post a Comment