javascript - SailsJs: How to access model from lifecycle callback? -



javascript - SailsJs: How to access model from lifecycle callback? -

let's have model called twins:

var model = module.exports = { attributes: { name: { type: 'string', } } aftercreate: function(twin){ twins.create({ name: twin.name + 'ii' }) } }

how access twins model object or, matter, model object within model lifecycle callback. writing twins not work in model file.

you can access model it. missed "exec()" @ create-function create never done.

try this:

aftercreate: function(twin){ twins.create({ name: twin.name + 'ii' }).exec(function(err,item){ if(err) homecoming sails.log.error(err); console.log(item); }); }

javascript node.js sails.js

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -