model.js
function(attrs, attrsToRemove) {
    _.forEach(attrs, function(val, key) {
      // shouldRemove is either an object or a boolean
      var shouldRemove = attrsToRemove[key];
      if (_.isUndefined(shouldRemove)) {
        return;
      }

      // Support nested object
      if (_.isPlainObject(val) && !_.isArray(val) && _.isPlainObject(shouldRemove)) {
        return this._removeExpandableAttributes(val, shouldRemove);
      }

      // Make sure attribute is an object
      // Strip all nested properties except for `_id`
      if (_.isPlainObject(attrs[key]) && shouldRemove) {
        attrs[key] = _.pick(attrs[key], ['_id']);
      }
    }.bind(this));
  }
function(attrs, attrsToRemove) {
    _.forEach(attrs, function(val, key) {
      // shouldRemove is either an object or a boolean
      var shouldRemove = attrsToRemove[key];
      if (_.isUndefined(shouldRemove)) {
        return;
      }

      // Support nested object
      if (_.isPlainObject(val) && !_.isArray(val) && _.isPlainObject(shouldRemove)) {
        return this._removeExpandableAttributes(val, shouldRemove);
      }

      // Make sure attribute is an object
      // Strip all nested properties except for `_id`
      if (_.isPlainObject(attrs[key]) && shouldRemove) {
        attrs[key] = _.pick(attrs[key], ['_id']);
      }
    }.bind(this));
  }
function ( attrs , attrsToRemove ) { _ . forEach ( attrs , function ( val , key ) { // shouldRemove is either an object or a boolean var shouldRemove = attrsToRemove [ key ] ; if ( _ . isUndefined ( shouldRemove ) ) { return ; } // Support nested object if ( _ . isPlainObject ( val ) && ! _ . isArray ( val ) && _ . isPlainObject ( shouldRemove ) ) { return this . _removeExpandableAttributes ( val , shouldRemove ) ; } // Make sure attribute is an object // Strip all nested properties except for `_id` if ( _ . isPlainObject ( attrs [ key ] ) && shouldRemove ) { attrs [ key ] = _ . pick ( attrs [ key ] , [ '_id' ] ) ; } } . bind ( this ) ) ; }
Remove expandable attributes

Does not work for objects embedded inside arrays

@param {Object} attrs
@param {Object} attrsToRemove
Remove expandable attributes