@@ -162,7 +162,9 @@ module.exports = function(AV) {
162162 . then ( function ( response ) {
163163 const results = _ . map ( objects , function ( object , i ) {
164164 if ( response [ i ] . success ) {
165- object . _finishFetch ( object . parse ( response [ i ] . success ) ) ;
165+ const fetchedAttrs = object . parse ( response [ i ] . success ) ;
166+ object . _cleanupUnsetKeys ( fetchedAttrs ) ;
167+ object . _finishFetch ( fetchedAttrs ) ;
166168 return object ;
167169 }
168170 if ( response [ i ] . success === null ) {
@@ -922,7 +924,7 @@ module.exports = function(AV) {
922924 * @return {Promise } A promise that is fulfilled when the fetch
923925 * completes.
924926 */
925- fetch : function ( fetchOptions , options ) {
927+ fetch : function ( fetchOptions = { } , options ) {
926928 var self = this ;
927929 var request = _request (
928930 'classes' ,
@@ -933,11 +935,19 @@ module.exports = function(AV) {
933935 options
934936 ) ;
935937 return request . then ( function ( response ) {
936- self . _finishFetch ( self . parse ( response ) , true ) ;
938+ const fetchedAttrs = self . parse ( response ) ;
939+ if ( ! fetchOptions . keys ) self . _cleanupUnsetKeys ( fetchedAttrs ) ;
940+ self . _finishFetch ( fetchedAttrs , true ) ;
937941 return self ;
938942 } ) ;
939943 } ,
940944
945+ _cleanupUnsetKeys ( fetchedAttrs ) {
946+ AV . _objectEach ( this . _serverData , ( value , key ) => {
947+ if ( fetchedAttrs [ key ] === undefined ) delete this . _serverData [ key ] ;
948+ } ) ;
949+ } ,
950+
941951 /**
942952 * Set a hash of model attributes, and save the model to the server.
943953 * updatedAt will be updated when the request returns.
0 commit comments