@@ -112,6 +112,9 @@ class ParseModel extends Model
112
112
113
113
const classNameOrParseObject = options . parseObject || options . className ;
114
114
115
+ Debug . log ( `ParseModel - ctor - 0 - options.parseObject: ${ options . parseObject } ` , true ) ;
116
+ Debug . log ( `ParseModel - ctor - 0 - options.className: ${ options . className } ` ) ;
117
+
115
118
if ( classNameOrParseObject instanceof Parse . Object )
116
119
{
117
120
const parseObject = classNameOrParseObject ;
@@ -128,6 +131,8 @@ class ParseModel extends Model
128
131
* @type {BackboneParseObject }
129
132
*/
130
133
this . parseObject = new BackboneParseObject ( parseObject . className , parseObject . attributes ) ;
134
+ this . parseObject . id = parseObject . id ;
135
+ this . parseObject . _localId = parseObject . _localId ;
131
136
132
137
adjustedClassName = this . parseObject . className ;
133
138
}
@@ -308,24 +313,6 @@ class ParseModel extends Model
308
313
return xhr ;
309
314
}
310
315
311
- /**
312
- * In order to deserialize Classes associated with `Parse.Object.registerSubclass()` this method is called and
313
- * the data must be forwarded onto the backing Parse.Object of ParseModel.
314
- *
315
- * @param {object } serverData - server data attributes.
316
- * @private
317
- */
318
- _finishFetch ( serverData )
319
- {
320
- this . parseObject . _finishFetch ( serverData ) ;
321
-
322
- const options = { updateParseObject : false } ;
323
-
324
- const attrs = this . parse ( this . parseObject , options ) || { } ;
325
-
326
- this . set ( attrs , options ) ;
327
- }
328
-
329
316
/**
330
317
* Has this model been saved to the server yet? If the model does not yet have an id, it is considered to be new.
331
318
*
@@ -355,9 +342,8 @@ class ParseModel extends Model
355
342
{
356
343
/* eslint-enable no-unused-vars */
357
344
358
- Debug . log ( `ParseModel - parse - 0 - resp instanceof Parse.Object: ${ resp instanceof Parse . Object } ` , true ) ;
359
-
360
- Debug . log ( `ParseModel - parse - 1 - ParseModel.prototype.idAttribute: ${ ParseModel . prototype . idAttribute } ` ) ;
345
+ Debug . log ( `ParseModel - parse - 0 - resp instanceof Parse.Object: ${ resp instanceof Parse . Object } ` , true ) ;
346
+ Debug . log ( `ParseModel - parse - 1 - ParseModel.prototype.idAttribute: ${ ParseModel . prototype . idAttribute } ` ) ;
361
347
362
348
let merged ;
363
349
@@ -373,21 +359,21 @@ class ParseModel extends Model
373
359
const mergeId = { } ;
374
360
mergeId [ ParseModel . prototype . idAttribute ] = this . id ;
375
361
376
- Debug . log ( `ParseModel - parse - 2 - mergeId: ${ mergeId [ ParseModel . prototype . idAttribute ] } ` ) ;
362
+ Debug . log ( `ParseModel - parse - 2 - mergeId: ${ mergeId [ ParseModel . prototype . idAttribute ] } ` ) ;
377
363
378
364
merged = _ . extend ( mergeId , resp . attributes ) ;
379
365
380
- Debug . log ( `ParseModel - parse - 3 - merged: ${ JSON . stringify ( merged ) } ` ) ;
366
+ Debug . log ( `ParseModel - parse - 3 - merged: ${ JSON . stringify ( merged ) } ` ) ;
381
367
}
382
368
else if ( _ . isObject ( resp ) )
383
369
{
384
370
const parseObjectId = resp [ ParseModel . prototype . idAttribute ] ;
385
371
386
- Debug . log ( `ParseModel - parse - 4 - resp is an Object / existing model - parseObjectId: ${ parseObjectId } ; resp: ${ JSON . stringify ( resp ) } ` ) ;
372
+ Debug . log ( `ParseModel - parse - 4 - resp is an Object / existing model - parseObjectId: ${ parseObjectId } ; resp: ${ JSON . stringify ( resp ) } ` ) ;
387
373
388
374
if ( ! _ . isUndefined ( parseObjectId ) && this . id !== parseObjectId )
389
375
{
390
- Debug . log ( `ParseModel - parse - 5 - this.id !== parseObjectId; this.id: ${ this . id } ; parseObjectId: ${ parseObjectId } ` ) ;
376
+ Debug . log ( `ParseModel - parse - 5 - this.id !== parseObjectId; this.id: ${ this . id } ; parseObjectId: ${ parseObjectId } ` ) ;
391
377
392
378
this . id = parseObjectId ;
393
379
}
@@ -453,38 +439,50 @@ class ParseModel extends Model
453
439
454
440
if ( Utils . isNullOrUndef ( key ) || typeof key === 'object' )
455
441
{
442
+ Debug . log ( `ParseModel - save - 0` ) ;
443
+
456
444
attrs = key ;
457
445
options = val ;
458
446
}
459
447
else
460
448
{
449
+ Debug . log ( `ParseModel - save - 1` ) ;
450
+
461
451
( attrs = { } ) [ key ] = val ;
462
452
}
463
453
464
454
// Save any previous options.success function.
465
455
const success = ! Utils . isNullOrUndef ( options ) ? options . success : undefined ;
466
456
467
- options = _ . extend (
457
+ Debug . log ( `ParseModel - save - 2 - options.success defined: ${ success !== undefined } ` ) ;
458
+
459
+ options = options || { } ;
460
+
461
+ options . success = ( model , resp , options ) =>
468
462
{
469
- success : ( model , resp , options ) =>
463
+ // Execute previously cached success function. Must do this first before resolving any potential
464
+ // child object changes.
465
+ if ( success )
470
466
{
471
- const modelAttrs = this . attributes ;
472
- for ( const attr in modelAttrs )
467
+ Debug . log ( 'ParseModel - save - 3 - invoking original options.success.' ) ;
468
+ success . call ( options . context , this , resp , options ) ;
469
+ }
470
+
471
+ Debug . log ( 'ParseModel - save - 4 - invoking ParseModel success.' ) ;
472
+
473
+ const modelAttrs = this . attributes ;
474
+ for ( const attr in modelAttrs )
475
+ {
476
+ const field = modelAttrs [ attr ] ;
477
+
478
+ // Here is the key part as if the associated Parse.Object id is different than the model id it
479
+ // needs to be parsed and data set to the Backbone.Model.
480
+ if ( field . parseObject && field . parseObject . id !== field . id )
473
481
{
474
- const field = modelAttrs [ attr ] ;
475
-
476
- // Here is the key part as if the associated Parse.Object id is different than the model id it
477
- // needs to be parsed and data set to the Backbone.Model.
478
- if ( field . parseObject && field . parseObject . id !== field . id )
479
- {
480
- field . set ( field . parse ( field . parseObject ) , options ) ;
481
- }
482
+ field . set ( field . parse ( field . parseObject ) , options ) ;
482
483
}
483
-
484
- // Execute previously cached success function.
485
- if ( success ) { success . call ( options . context , this , resp , options ) ; }
486
484
}
487
- } , options ) ;
485
+ } ;
488
486
489
487
return super . save ( attrs , options ) ;
490
488
}
@@ -536,7 +534,7 @@ class ParseModel extends Model
536
534
const changing = this . _changing ;
537
535
this . _changing = true ;
538
536
539
- Debug . log ( `ParseModel - set - 0 - changing: ${ changing } ; attrs: ${ JSON . stringify ( attrs ) } ; options: ${ JSON . stringify ( options ) } ` , true ) ;
537
+ Debug . log ( `ParseModel - set - 0 - changing: ${ changing } ; attrs: ${ JSON . stringify ( attrs ) } ; options: ${ JSON . stringify ( options ) } ` , true ) ;
540
538
541
539
if ( ! changing )
542
540
{
@@ -555,22 +553,22 @@ class ParseModel extends Model
555
553
556
554
if ( ! _ . isEqual ( current [ attr ] , val ) )
557
555
{
558
- Debug . log ( `ParseModel - set - 1 - current[attr] != val for key: ${ attr } ` ) ;
556
+ Debug . log ( `ParseModel - set - 1 - current[attr] != val for key: ${ attr } ` ) ;
559
557
changes . push ( attr ) ;
560
558
}
561
559
562
560
let actuallyChanged = false ;
563
561
564
562
if ( ! _ . isEqual ( prev [ attr ] , val ) )
565
563
{
566
- Debug . log ( `ParseModel - set - 2 - prev[attr] != val for key: ${ attr } ` ) ;
564
+ Debug . log ( `ParseModel - set - 2 - prev[attr] != val for key: ${ attr } ` ) ;
567
565
568
566
changed [ attr ] = val ;
569
567
actuallyChanged = true ;
570
568
}
571
569
else
572
570
{
573
- Debug . log ( `ParseModel - set - 3 - prev[attr] == val delete changed for key: ${ attr } ` ) ;
571
+ Debug . log ( `ParseModel - set - 3 - prev[attr] == val delete changed for key: ${ attr } ` ) ;
574
572
delete changed [ attr ] ;
575
573
}
576
574
@@ -589,7 +587,7 @@ class ParseModel extends Model
589
587
// Parse.Object returns itself on success
590
588
unsetSuccess = this . parseObject === this . parseObject . unset ( attr ) ;
591
589
592
- Debug . log ( `ParseModel - set - 4 - unset Parse.Object - attr: ${ attr } ; unsetSuccess: ${ unsetSuccess } ` ) ;
590
+ Debug . log ( `ParseModel - set - 4 - unset Parse.Object - attr: ${ attr } ; unsetSuccess: ${ unsetSuccess } ` ) ;
593
591
}
594
592
595
593
if ( unsetSuccess )
@@ -599,15 +597,15 @@ class ParseModel extends Model
599
597
}
600
598
else
601
599
{
602
- let setSuccess = ! updateParseObject ;
600
+ let setSuccess = ! updateParseObject || attr === ParseModel . prototype . idAttribute ;
603
601
604
602
if ( actuallyChanged && updateParseObject && this . parseObject !== null &&
605
603
attr !== ParseModel . prototype . idAttribute )
606
604
{
607
605
// Parse.Object returns itself on success
608
606
setSuccess = this . parseObject === this . parseObject . set ( attr , val , options ) ;
609
607
610
- Debug . log ( `ParseModel - set - 5 - set Parse.Object - attr: ${ attr } ; setSuccess: ${ setSuccess } ` ) ;
608
+ Debug . log ( `ParseModel - set - 5 - set Parse.Object - attr: ${ attr } ; setSuccess: ${ setSuccess } ` ) ;
611
609
}
612
610
613
611
if ( actuallyChanged && setSuccess )
@@ -624,7 +622,7 @@ class ParseModel extends Model
624
622
for ( let i = 0 ; i < changes . length ; i ++ )
625
623
{
626
624
this . trigger ( `change:${ changes [ i ] } ` , this , current [ changes [ i ] ] , options ) ;
627
- Debug . log ( `ParseModel - set - 6 - trigger - changeKey: ${ changes [ i ] } ` ) ;
625
+ Debug . log ( `ParseModel - set - 6 - trigger - changeKey: ${ changes [ i ] } ` ) ;
628
626
}
629
627
}
630
628
@@ -638,26 +636,14 @@ class ParseModel extends Model
638
636
options = this . _pending ;
639
637
this . _pending = false ;
640
638
this . trigger ( 'change' , this , options ) ;
641
- Debug . log ( `ParseModel - set - 7 - trigger - change` ) ;
639
+ Debug . log ( `ParseModel - set - 7 - trigger - change` ) ;
642
640
}
643
641
}
644
642
this . _pending = false ;
645
643
this . _changing = false ;
646
644
return this ;
647
645
}
648
646
649
- /**
650
- * In order to deserialize Classes associated with `Parse.Object.registerSubclass()` this method is called and
651
- * the data must be forwarded onto the backing Parse.Object of ParseModel.
652
- *
653
- * @param {boolean } existed - Sets the existed state.
654
- * @private
655
- */
656
- _setExisted ( existed )
657
- {
658
- this . parseObject . _setExisted ( existed ) ;
659
- }
660
-
661
647
/**
662
648
* Return a copy of the model's `attributes` object.
663
649
*
0 commit comments