File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed
-ember-data/tests/integration
store/addon/-private/system Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -373,6 +373,42 @@ module('integration/snapshot - Snapshot', function(hooks) {
373
373
assert . equal ( relationship . attr ( 'title' ) , 'Hello World' , 'post title is correct' ) ;
374
374
} ) ;
375
375
376
+ test ( 'snapshot.belongsTo().changedAttributes() returns an empty object if belongsTo record in not instantiated #7015' , function ( assert ) {
377
+ assert . expect ( 2 ) ;
378
+
379
+ store . push ( {
380
+ data : [
381
+ {
382
+ type : 'comment' ,
383
+ id : '2' ,
384
+ attributes : {
385
+ body : 'This is comment' ,
386
+ } ,
387
+ relationships : {
388
+ post : {
389
+ data : { type : 'post' , id : '1' } ,
390
+ } ,
391
+ } ,
392
+ } ,
393
+ ] ,
394
+ included : [
395
+ {
396
+ type : 'post' ,
397
+ id : '1' ,
398
+ attributes : {
399
+ title : 'Hello World' ,
400
+ } ,
401
+ } ,
402
+ ] ,
403
+ } ) ;
404
+ let comment = store . peekRecord ( 'comment' , 2 ) ;
405
+ let snapshot = comment . _createSnapshot ( ) ;
406
+ let relationship = snapshot . belongsTo ( 'post' ) ;
407
+
408
+ assert . ok ( relationship instanceof Snapshot , 'snapshot is an instance of Snapshot' ) ;
409
+ assert . deepEqual ( relationship . changedAttributes ( ) , { } , 'changedAttributes are correct' ) ;
410
+ } ) ;
411
+
376
412
test ( 'snapshot.belongsTo() returns null if relationship is deleted' , function ( assert ) {
377
413
assert . expect ( 1 ) ;
378
414
Original file line number Diff line number Diff line change @@ -119,7 +119,6 @@ export default class Snapshot implements Snapshot {
119
119
@type {String }
120
120
*/
121
121
this . modelName = internalModel . modelName ;
122
-
123
122
if ( internalModel . hasRecord ) {
124
123
this . _changedAttributes = recordDataFor ( internalModel ) . changedAttributes ( ) ;
125
124
}
@@ -246,6 +245,10 @@ export default class Snapshot implements Snapshot {
246
245
*/
247
246
changedAttributes ( ) : ChangedAttributesHash {
248
247
let changedAttributes = Object . create ( null ) ;
248
+ if ( ! this . _changedAttributes ) {
249
+ return changedAttributes ;
250
+ }
251
+
249
252
let changedAttributeKeys = Object . keys ( this . _changedAttributes ) ;
250
253
251
254
for ( let i = 0 , length = changedAttributeKeys . length ; i < length ; i ++ ) {
You can’t perform that action at this time.
0 commit comments