File tree Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Expand file tree Collapse file tree 1 file changed +23
-0
lines changed Original file line number Diff line number Diff line change @@ -4852,6 +4852,29 @@ describe('Model', function() {
4852
4852
} ) ;
4853
4853
} ) ;
4854
4854
4855
+ it ( 'run default function with correct this scope in DocumentArray (gh-6840)' , function ( ) {
4856
+ var schema = new Schema ( {
4857
+ title : String ,
4858
+ actors : {
4859
+ type : [ { name : String , character : String } ] ,
4860
+ default : function ( ) {
4861
+ // `this` should be root document and has initial data
4862
+ if ( this . title === 'Passenger' ) {
4863
+ return [
4864
+ { name : 'Jennifer Lawrence' , character : 'Aurora Lane' } ,
4865
+ { name : 'Chris Pratt' , character : 'Jim Preston' }
4866
+ ] ;
4867
+ }
4868
+ return [ ] ;
4869
+ }
4870
+ }
4871
+ } ) ;
4872
+
4873
+ var Movie = db . model ( 'gh6840' , schema ) ;
4874
+ var movie = new Movie ( { title : 'Passenger' } ) ;
4875
+ assert . equal ( movie . actors . length , 2 ) ;
4876
+ } ) ;
4877
+
4855
4878
describe ( '3.6 features' , function ( ) {
4856
4879
before ( function ( done ) {
4857
4880
start . mongodVersion ( ( err , version ) => {
You can’t perform that action at this time.
0 commit comments