server/models/helpers/component-from-model.js
function(res, scContent, post, cb) {
      let model = this._modelInfo(scContent['forModel']);
      // get list of expected model props
      let fields = this.makeFormFields(res, scContent);
      let data = {};
      let where = null;
      _.forEach(fields, function(val) {
        if (val.isId) {
          if (post[val.name]) where = {[val.name]: post[val.name]}
        }
        else if (val.name in post) {
          if (val.embedIn) {
            data[val.embedIn] = Object.assign({}, data[val.embedIn],
              {[val.name]: post[val.name]});
          }
          else data[val.name] = post[val.name];
        }
      });
      // add forceVals
      if (scContent.forceVals) {
        _.forEach(scContent.forceVals, function(val, key) {
          data[key] = val;
        });
      }
      // save data
      if (where) {
        // update existing
        model.model.upsertWithWhere(where, data, (err, inst) => {
          cb(err, inst);
        });
      }
      else {
        model.model.create(data, (err, inst) => {
          cb(err, inst);
        });
      }
    }
function(res, scContent, post, cb) {
      let model = this._modelInfo(scContent['forModel']);
      // get list of expected model props
      let fields = this.makeFormFields(res, scContent);
      let data = {};
      let where = null;
      _.forEach(fields, function(val) {
        if (val.isId) {
          if (post[val.name]) where = {[val.name]: post[val.name]}
        }
        else if (val.name in post) {
          if (val.embedIn) {
            data[val.embedIn] = Object.assign({}, data[val.embedIn],
              {[val.name]: post[val.name]});
          }
          else data[val.name] = post[val.name];
        }
      });
      // add forceVals
      if (scContent.forceVals) {
        _.forEach(scContent.forceVals, function(val, key) {
          data[key] = val;
        });
      }
      // save data
      if (where) {
        // update existing
        model.model.upsertWithWhere(where, data, (err, inst) => {
          cb(err, inst);
        });
      }
      else {
        model.model.create(data, (err, inst) => {
          cb(err, inst);
        });
      }
    }
function ( res , scContent , post , cb ) { let model = this . _modelInfo ( scContent [ 'forModel' ] ) ; // get list of expected model props let fields = this . makeFormFields ( res , scContent ) ; let data = { } ; let where = null ; _ . forEach ( fields , function ( val ) { if ( val . isId ) { if ( post [ val . name ] ) where = { [ val . name ] : post [ val . name ] } } else if ( val . name in post ) { if ( val . embedIn ) { data [ val . embedIn ] = Object . assign ( { } , data [ val . embedIn ] , { [ val . name ] : post [ val . name ] } ) ; } else data [ val . name ] = post [ val . name ] ; } } ) ; // add forceVals if ( scContent . forceVals ) { _ . forEach ( scContent . forceVals , function ( val , key ) { data [ key ] = val ; } ) ; } // save data if ( where ) { // update existing model . model . upsertWithWhere ( where , data , ( err , inst ) => { cb ( err , inst ) ; } ) ; } else { model . model . create ( data , ( err , inst ) => { cb ( err , inst ) ; } ) ; } }
save posted data for Form Component from model
save posted data for Form Component from model