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
Post a Comment