@@ -3,6 +3,13 @@ const AVError = require('./error');
33const AVRequest = require ( './request' ) . request ;
44const utils = require ( './utils' ) ;
55
6+ const RESERVED_KEYS = [ 'objectId' , 'createdAt' , 'updatedAt' ] ;
7+ const checkReservedKey = key => {
8+ if ( RESERVED_KEYS . indexOf ( key ) !== - 1 ) {
9+ throw new Error ( `key[${ key } ] is reserved` ) ;
10+ }
11+ } ;
12+
613// AV.Object is analogous to the Java AVObject.
714// It also implements the same interface as a Backbone model.
815
@@ -289,7 +296,6 @@ module.exports = function(AV) {
289296 get : function ( attr ) {
290297 switch ( attr ) {
291298 case 'objectId' :
292- case 'id' :
293299 return this . id ;
294300 case 'createdAt' :
295301 case 'updatedAt' :
@@ -355,16 +361,16 @@ module.exports = function(AV) {
355361 _mergeMagicFields : function ( attrs ) {
356362 // Check for changes of magic fields.
357363 var model = this ;
358- var specialFields = [ "id" , " objectId", "createdAt" , "updatedAt" ] ;
364+ var specialFields = [ "objectId" , "createdAt" , "updatedAt" ] ;
359365 AV . _arrayEach ( specialFields , function ( attr ) {
360366 if ( attrs [ attr ] ) {
361367 if ( attr === "objectId" ) {
362368 model . id = attrs [ attr ] ;
363369 } else if ( ( attr === "createdAt" || attr === "updatedAt" ) &&
364370 ! _ . isDate ( attrs [ attr ] ) ) {
365371 model [ attr ] = AV . _parseDate ( attrs [ attr ] ) ;
366- } else {
367- model [ attr ] = attrs [ attr ] ;
372+ } else {
373+ model [ attr ] = attrs [ attr ] ;
368374 }
369375 delete attrs [ attr ] ;
370376 }
@@ -604,11 +610,13 @@ module.exports = function(AV) {
604610 if ( _ . isObject ( key ) || utils . isNullOrUndefined ( key ) ) {
605611 attrs = key ;
606612 AV . _objectEach ( attrs , function ( v , k ) {
613+ checkReservedKey ( k ) ;
607614 attrs [ k ] = AV . _decode ( k , v ) ;
608615 } ) ;
609616 options = value ;
610617 } else {
611618 attrs = { } ;
619+ checkReservedKey ( key ) ;
612620 attrs [ key ] = AV . _decode ( key , value ) ;
613621 }
614622
0 commit comments