lib/services/model_factory.js
function(instance) {
      var loadData = function(data) {
        return _.extend(instance, data);
      };

      if (instance.id) {
        // do PUT save
        return api
          .one(config.entity, instance.id)
          .put(instance)
          .then(loadData, console.error);
      } else {
        // no id is set, do a POST
        var endpoint = api;
        if (config.parent) {
          endpoint.one(config.parent.entity, instance[config.parent.key]);
        }
        endpoint.all(config.entity);

        return endpoint
          .post(instance)
          .then(loadData, console.error);
      }
    }
function(instance) {
      var loadData = function(data) {
        return _.extend(instance, data);
      };

      if (instance.id) {
        // do PUT save
        return api
          .one(config.entity, instance.id)
          .put(instance)
          .then(loadData, console.error);
      } else {
        // no id is set, do a POST
        var endpoint = api;
        if (config.parent) {
          endpoint.one(config.parent.entity, instance[config.parent.key]);
        }
        endpoint.all(config.entity);

        return endpoint
          .post(instance)
          .then(loadData, console.error);
      }
    }
function ( instance ) { var loadData = function ( data ) { return _ . extend ( instance , data ) ; } ; if ( instance . id ) { // do PUT save return api . one ( config . entity , instance . id ) . put ( instance ) . then ( loadData , console . error ) ; } else { // no id is set, do a POST var endpoint = api ; if ( config . parent ) { endpoint . one ( config . parent . entity , instance [ config . parent . key ] ) ; } endpoint . all ( config . entity ) ; return endpoint . post ( instance ) . then ( loadData , console . error ) ; } }
Persists entity using rest API

@param {Model} instance
@return {Promise}
Persists entity using rest API