View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page

* .save(callback)

Purpose

The save() method updates your record in the database using the current attributes. It then returns the newly saved object in the callback.

Overview

Parameters

Description Accepted Data Types Required ?
1 Callback function Yes

Callback Parameters

Description Possible Data Types
1 Error Error
2 Saved Record { }

Example Usage

User.find().exec(
  function(err,myRecords){

    // Grab a record off the top of the returned array and save a new attribute to it
    var getOneRecord = myRecords.pop();
    getOneRecord.name = 'Hank';
    getOneRecord.save(
      function(err,s){
        console.log('User with ID '+s.id+' now has name '+s.name);
      });
  });

// User with ID 1 now has name Hank

// Don't forget to handle your errors.
// Don't forget to abide by the rules you set in your model

Notes

This is an instance method. Currently, instance methods ARE NOT TRANSACTIONAL. Because of this, it is recommended that you use the equivalent model method instead.

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.

Reference

We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book