@@ -12627,6 +12627,41 @@ describe('document', function() {
1262712627    doc . set ( 'branding.logo.attachment' ,  {  name : 'coolLogo'  } ) ; 
1262812628    await  doc . save ( ) ; 
1262912629    assert . strictEqual ( attachmentSchemaPreValidateCalls ,  1 ) ; 
12630+ 
12631+     instance . set ( 'branding.logo.attachment' ,  {  name : 'coolOtherLogo'  } ) ; 
12632+     await  instance . save ( ) ; 
12633+     assert . strictEqual ( attachmentSchemaPreValidateCalls ,  2 ) ; 
12634+   } ) ; 
12635+ 
12636+   it ( 'fires pre validate hooks on 5 level deep single nested subdoc when modifying after save() (gh-14591)' ,  async  function ( )  { 
12637+     let  preValidate  =  [ ] ; 
12638+ 
12639+     const  createSchema  =  ( path ,  subSchema )  =>  { 
12640+       const  schema  =  new  Schema ( {  [ path ] : subSchema  } ) ; 
12641+       schema . pre ( 'validate' ,  function ( )  { 
12642+         preValidate . push ( path ) ; 
12643+       } ) ; 
12644+       return  schema ; 
12645+     } ; 
12646+ 
12647+     const  e  =  createSchema ( 'e' ,  {  type : String  } ) ; 
12648+     const  d  =  createSchema ( 'd' ,  {  type : e  } ) ; 
12649+     const  c  =  createSchema ( 'c' ,  {  type : d  } ) ; 
12650+     const  b  =  createSchema ( 'b' ,  {  type : c  } ) ; 
12651+     const  a  =  createSchema ( 'a' ,  {  type : b  } ) ; 
12652+     b . add ( {  otherProp : String  } ) ; 
12653+     const  NestedModelHooksTestModel  =  db . model ( 'Test' ,  a ) ; 
12654+ 
12655+     const  newData  =  {  a : {  b : {  c : {  d : {  e : new  Date ( ) . toString ( )  }  }  }  }  } ; 
12656+     newData . a . otherProp  =  'test' ; 
12657+     const  doc  =  await  new  NestedModelHooksTestModel ( newData ) . save ( ) ; 
12658+     preValidate  =  [ ] ; 
12659+     doc . set ( {  'a.b.c.d.e' : 'updated nested value'  } ) ; 
12660+     await  doc . save ( ) ; 
12661+     assert . deepStrictEqual ( preValidate ,  [ 'a' ,  'b' ,  'c' ,  'd' ,  'e' ] ) ; 
12662+ 
12663+     const  fromDb  =  await  NestedModelHooksTestModel . findById ( doc . _id ) ; 
12664+     assert . strictEqual ( fromDb . a . otherProp ,  'test' ) ; 
1263012665  } ) ; 
1263112666
1263212667  it ( 'returns constructor if using $model() with no args (gh-13878)' ,  async  function ( )  { 
0 commit comments