@@ -212,6 +212,7 @@ export default Component.extend({
212
212
* @param {(Object|Object[]|Record|Record[]) } data The record or records to insert.
213
213
* @param {Object } [opts] Configuration options.
214
214
* @param {boolean } [opts.commitOnMerge=true] See {@link Collection#commitOnMerge}.
215
+ * @param {boolean } [opts.noValidate] See {@link Mapper#noValidate}.
215
216
* @param {string } [opts.onConflict] See {@link Collection#onConflict}.
216
217
* @returns {(Object|Object[]|Record|Record[]) } The added record or records.
217
218
*/
@@ -253,6 +254,12 @@ export default Component.extend({
253
254
// Here, the currently visited record corresponds to a record already
254
255
// in the collection, so we need to merge them
255
256
const onConflict = opts . onConflict || this . onConflict
257
+ let restoreNoValidate
258
+ // `noValidate` might have been overriden in find/findAll. respect that
259
+ if ( opts . noValidate !== undefined ) {
260
+ restoreNoValidate = existing . _set . bind ( existing , 'noValidate' , existing . _get ( 'noValidate' ) )
261
+ existing . _set ( 'noValidate' , opts . noValidate )
262
+ }
256
263
if ( onConflict === 'merge' ) {
257
264
utils . deepMixIn ( existing , record )
258
265
} else if ( onConflict === 'replace' ) {
@@ -263,8 +270,12 @@ export default Component.extend({
263
270
} )
264
271
existing . set ( record )
265
272
} else {
273
+ // restore prev `noValidate` before throwing if it was overriden for the record
274
+ utils . isFunction ( restoreNoValidate ) && restoreNoValidate ( )
266
275
throw utils . err ( `${ DOMAIN } #add` , 'opts.onConflict' ) ( 400 , 'one of (merge, replace)' , onConflict , true )
267
276
}
277
+ // restore prev `noValidate` value if it was overriden for the record
278
+ utils . isFunction ( restoreNoValidate ) && restoreNoValidate ( )
268
279
record = existing
269
280
if ( opts . commitOnMerge && utils . isFunction ( record . commit ) ) {
270
281
record . commit ( )
0 commit comments