File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1311,7 +1311,7 @@ function set(model, values = {}) {
13111311 if ( ! isDraft && values && hasOwnProperty . call ( values , "id" ) ) {
13121312 if ( ! config . enumerable ) {
13131313 throw TypeError ( `Values must not contain 'id' property: ${ values . id } ` ) ;
1314- } else if ( ! isInstance || values . id !== model . id ) {
1314+ } else if ( isInstance && values . id !== model . id ) {
13151315 throw TypeError (
13161316 `You cannot change the 'id' property of the model instance: ${ values . id } ` ,
13171317 ) ;
Original file line number Diff line number Diff line change @@ -383,10 +383,6 @@ describe("store:", () => {
383383 expect ( ( ) => store . set ( Model , { id : "test" } ) ) . toThrow ( ) ;
384384 } ) ;
385385
386- it ( "throws an error when values contain 'id' property for enumerable model" , async ( ) => {
387- expect ( ( ) => store . set ( Model , { id : "test" } ) ) . toThrow ( ) ;
388- } ) ;
389-
390386 it ( "throws an error when updating an instance and values contain different 'id' property" , async ( ) => {
391387 const model = await promise ;
392388 expect ( ( ) => store . set ( model , { ...model , id : "different" } ) ) . toThrow ( ) ;
@@ -500,6 +496,14 @@ describe("store:", () => {
500496 expect ( model . nestedArrayOfObjects [ 0 ] . id ) . not . toBeDefined ( ) ;
501497 } ) ) ;
502498
499+ it ( 'uses provided id for objects with "id" key' , ( ) =>
500+ store
501+ . set ( Model , { id : 123 , nestedArrayOfExternalObjects : [ { id : 456 } ] } )
502+ . then ( ( model ) => {
503+ expect ( model . id ) . toBe ( "123" ) ;
504+ expect ( model . nestedArrayOfExternalObjects [ 0 ] . id ) . toBe ( "456" ) ;
505+ } ) ) ;
506+
503507 it ( "updates single property" , ( ) =>
504508 promise . then ( ( model ) =>
505509 store . set ( model , { string : "new value" } ) . then ( ( newModel ) => {
You can’t perform that action at this time.
0 commit comments