File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -42,8 +42,11 @@ function applyGetters(schema, res) {
42
42
if ( res == null ) {
43
43
return ;
44
44
}
45
+ if ( ! this . _mongooseOptions ?. lean ) {
46
+ return ;
47
+ }
45
48
const { defaultLeanOptions } = this . _mongooseLeanGettersOptions ;
46
- const shouldCallGetters = this . _mongooseOptions ? .lean ? .getters ?? defaultLeanOptions ?. getters ?? false ;
49
+ const shouldCallGetters = this . _mongooseOptions . lean . getters ?? defaultLeanOptions ?. getters ?? false ;
47
50
48
51
if ( shouldCallGetters ) {
49
52
if ( Array . isArray ( res ) ) {
Original file line number Diff line number Diff line change @@ -442,7 +442,8 @@ describe('mongoose-lean-getters', function() {
442
442
assert . equal ( typeof found . discriminatedProp . num , 'string' , 'Discriminated prop is not a string' ) ;
443
443
assert . equal ( typeof found . discriminatedArray [ 0 ] . num , 'string' , 'Discriminated array is not a string' ) ;
444
444
} ) ;
445
- it ( 'allows defaultLeanOptions to be set and overridden at call time (#33)' , async ( ) => {
445
+
446
+ it ( 'allows defaultLeanOptions to be set and overridden at call time (#33) (#46)' , async ( ) => {
446
447
const testSchema = new mongoose . Schema ( {
447
448
field : {
448
449
type : String ,
@@ -458,6 +459,10 @@ describe('mongoose-lean-getters', function() {
458
459
459
460
const doc2 = await TestModel . findById ( entry . _id ) . lean ( { getters : false } ) ;
460
461
assert . equal ( doc2 . field , 'value' ) ;
462
+
463
+ const doc3 = await TestModel . findById ( entry . _id ) ;
464
+ assert . equal ( doc3 . field , 'value-suffix' ) ;
465
+ assert . equal ( doc3 . get ( 'field' , null , { getters : false } ) , 'value' ) ;
461
466
} ) ;
462
467
463
468
it ( 'should allow non-discriminated documents to be retrieved (#39)' , async ( ) => {
You can’t perform that action at this time.
0 commit comments