user3426711 user3426711 - 1 year ago 82
Node.js Question

Get inserted record in Waterline

How to get the inserted record in Waterline?

Note: I am using sails.js

My code :

}).exec(function createdFile(err, _record){
return _record;

is always
but it is inserted in the DB, I want to return the inserted record in json to the client after the insert. (


Answer Source

Record will be undefined as you are probably using the value prior to the callback completing. You need to reference _record as this is the created record within the callback after the create. You will need to nest inside to use the returned record e.g. do res.view('page',{message: _record});

Example usage:


        }).exec(function createdFile(err, _record){

          return res.json({message: _record});
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download