File tree Expand file tree Collapse file tree 4 files changed +33
-18
lines changed
Expand file tree Collapse file tree 4 files changed +33
-18
lines changed Original file line number Diff line number Diff line change @@ -323,8 +323,8 @@ module.exports = function(AV) {
323323 * if (fileUploadControl.files.length > 0) {
324324 * var file = fileUploadControl.files[0];
325325 * var name = "photo.jpg";
326- * var parseFile = new AV.File(name, file);
327- * parseFile .save().then(function() {
326+ * var file = new AV.File(name, file);
327+ * file .save().then(function() {
328328 * // The file has been saved to AV.
329329 * }, function(error) {
330330 * // The file either could not be read, or could not be saved to AV.
Original file line number Diff line number Diff line change @@ -927,9 +927,14 @@ module.exports = function(AV) {
927927 json . _fetchWhenSave = true ;
928928 }
929929 if ( options . query ) {
930- try {
931- json . _where = options . query . toJSON ( ) . where ;
932- } catch ( e ) {
930+ var queryJSON ;
931+ if ( typeof options . query . toJSON === 'function' ) {
932+ queryJSON = options . query . toJSON ( ) ;
933+ if ( queryJSON ) {
934+ json . _where = queryJSON . where ;
935+ }
936+ }
937+ if ( ! json . _where ) {
933938 var error = new Error ( 'options.query is not an AV.Query' ) ;
934939 return AV . Promise . error ( error ) . _thenRunCallbacks ( options , model ) ;
935940 }
Original file line number Diff line number Diff line change @@ -378,13 +378,14 @@ const init = (AV) => {
378378 if ( objectId ) {
379379 apiURL += "/" + objectId ;
380380 }
381- if ( ( route === 'users' || route === 'classes' ) && dataObject ) {
381+ if ( ( route === 'users' || route === 'classes' ) && dataObject ) {
382+ apiURL += '?' ;
382383 if ( dataObject . _fetchWhenSave ) {
383384 delete dataObject . _fetchWhenSave ;
384- apiURL += '? new=true' ;
385+ apiURL += '& new=true' ;
385386 }
386387 if ( dataObject . _where ) {
387- apiURL += ( '? where=' + encodeURIComponent ( JSON . stringify ( dataObject . _where ) ) ) ;
388+ apiURL += ( '& where=' + encodeURIComponent ( JSON . stringify ( dataObject . _where ) ) ) ;
388389 delete dataObject . _where ;
389390 }
390391 }
Original file line number Diff line number Diff line change @@ -119,17 +119,26 @@ describe('Objects', function(){
119119 }
120120 } ) ;
121121 } ) ;
122- it ( " should not update prop when query not match" , function ( done ) {
123- gameScore . set ( " score" , 10000 ) ;
122+ it ( ' should not update prop when query not match' , function ( done ) {
123+ gameScore . set ( ' score' , 10000 ) ;
124124 gameScore . save ( null , {
125- query : new AV . Query ( GameScore ) . equalTo ( 'score' , - 1 ) ,
126- success : function ( result ) {
127- done ( new Error ( 'should not success' ) ) ;
128- } ,
129- error : function ( gameScore , error ) {
130- expect ( error . code ) . to . be . eql ( 305 ) ;
131- done ( ) ;
132- }
125+ query : new AV . Query ( GameScore ) . equalTo ( 'score' , - 1 )
126+ } ) . then ( function ( result ) {
127+ done ( new Error ( 'should not success' ) ) ;
128+ } , function ( error ) {
129+ expect ( error . code ) . to . be . eql ( 305 ) ;
130+ done ( ) ;
131+ } ) ;
132+ } ) ;
133+ it ( 'should update prop when query match' , function ( done ) {
134+ gameScore . set ( 'score' , 10000 ) ;
135+ gameScore . save ( null , {
136+ query : new AV . Query ( GameScore ) . notEqualTo ( 'score' , - 1 ) ,
137+ fetchWhenSave : true
138+ } ) . then ( function ( result ) {
139+ done ( ) ;
140+ } , function ( error ) {
141+ done ( error ) ;
133142 } ) ;
134143 } ) ;
135144 } ) ;
You can’t perform that action at this time.
0 commit comments