File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -55,8 +55,18 @@ export default class ValidationErrors {
55
55
} else {
56
56
let relatedAccumulator = { }
57
57
this . _processResource ( relatedAccumulator , meta ) ;
58
- relatedObject . errors = relatedAccumulator
59
- }
60
58
59
+ // make sure to assign a new error object, instead of mutating
60
+ // the existing one, otherwise js frameworks with object tracking
61
+ // won't be able to keep up. Validate vue.js when changing this code:
62
+ let newErrs = { }
63
+ Object . keys ( relatedObject . errors ) . forEach ( ( key ) => {
64
+ newErrs [ key ] = relatedObject . errors [ key ]
65
+ } ) ;
66
+ Object . keys ( relatedAccumulator ) . forEach ( ( key ) => {
67
+ newErrs [ key ] = relatedAccumulator [ key ]
68
+ } ) ;
69
+ relatedObject . errors = newErrs
70
+ }
61
71
}
62
72
}
Original file line number Diff line number Diff line change @@ -59,6 +59,26 @@ const resetMocks = function() {
59
59
}
60
60
}
61
61
}
62
+ } ,
63
+ {
64
+ code : 'unprocessable_entity' ,
65
+ status : '422' ,
66
+ title : 'Validation Error' ,
67
+ detail : 'base some error' ,
68
+ meta : {
69
+ relationship : {
70
+ name : 'books' ,
71
+ type : 'books' ,
72
+ [ 'temp-id' ] : 'abc1' ,
73
+ relationship : {
74
+ name : 'genre' ,
75
+ type : 'genres' ,
76
+ id : '1' ,
77
+ attribute : 'base' ,
78
+ message : 'some error'
79
+ }
80
+ }
81
+ }
62
82
}
63
83
]
64
84
}
@@ -176,8 +196,11 @@ describe('validations', function() {
176
196
instance . save ( { with : { books : 'genre' } } ) . then ( ( success ) => {
177
197
expect ( instance . isPersisted ( ) ) . to . eq ( false ) ;
178
198
expect ( success ) . to . eq ( false ) ;
199
+
200
+ // note we're validating multiple properties
179
201
expect ( instance . books [ 0 ] . genre . errors ) . to . deep . equal ( {
180
202
name : 'cannot be blank' ,
203
+ base : 'some error'
181
204
} ) ;
182
205
done ( ) ;
183
206
} ) ;
You can’t perform that action at this time.
0 commit comments