sails.js Use session param in model

So, if I understand you correctly, you want to avoid lots of code like this in your controllers: SomeModel.create({companyId: req.session.companyId, …}) SomeModel.find({companyId: req.session.companyId, …}) Fair enough. Maybe you’re concerned that companyId will be renamed in the future, or need to be further processed. The simplest solution if you’re using custom controller actions would be to … Read more

Auto reloading a Sails.js app on code changes?

You have to use a watcher like forever, nodemon, or something else… Example Install forever by running: sudo npm install -g forever Run it: forever -w start app.js To avoid infinite restart because Sails writes into .tmp folder, you can create a .foreverignore file into your project directory and put this content inside: **/.tmp/** **/views/** … Read more

CRUD blueprint overriding in sails.js

Update In order to override blueprints in Sails 1.0 in the manner described below, you must first install the “custom blueprints” plugin for your project (npm install sails-hook-custom-blueprints). To override blueprints in Sails v0.10, you create an api/blueprints folder and add your blueprint files (e.g. find.js, create.js, etc.) within. You can take a look at … Read more

Sails.js populate nested associations

Or you can use the built-in Blue Bird Promise feature to make it. (Working on [email protected]) See the codes below: var _ = require(‘lodash’); … Post .findOne(req.param(‘id’)) .populate(‘user’) .populate(‘comments’) .then(function(post) { var commentUsers = User.find({ id: _.pluck(post.comments, ‘user’) //_.pluck: Retrieves the value of a ‘user’ property from all elements in the post.comments collection. }) .then(function(commentUsers) … Read more