File tree 2 files changed +9
-1
lines changed
2 files changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -1952,6 +1952,7 @@ Schema.prototype.plugin = function(fn, opts) {
1952
1952
'got "' + ( typeof fn ) + '"' ) ;
1953
1953
}
1954
1954
1955
+
1955
1956
if ( opts && opts . deduplicate ) {
1956
1957
for ( const plugin of this . plugins ) {
1957
1958
if ( plugin . fn === fn ) {
@@ -2755,7 +2756,7 @@ function isArrayFilter(piece) {
2755
2756
*/
2756
2757
2757
2758
Schema . prototype . _preCompile = function _preCompile ( ) {
2758
- idGetter ( this ) ;
2759
+ this . plugin ( idGetter , { deduplicate : true } ) ;
2759
2760
} ;
2760
2761
2761
2762
/*!
Original file line number Diff line number Diff line change @@ -3172,6 +3172,13 @@ describe('schema', function() {
3172
3172
const res = await Test . findOne ( { _id : { $eq : doc . _id , $type : 'objectId' } } ) ;
3173
3173
assert . equal ( res . name , 'Test Testerson' ) ;
3174
3174
} ) ;
3175
+ it ( 'deduplicates idGetter (gh-14457)' , function ( ) {
3176
+ const schema = new Schema ( { name : String } ) ;
3177
+ schema . _preCompile ( ) ;
3178
+ assert . equal ( schema . virtual ( 'id' ) . getters . length , 1 ) ;
3179
+ schema . _preCompile ( ) ;
3180
+ assert . equal ( schema . virtual ( 'id' ) . getters . length , 1 ) ;
3181
+ } ) ;
3175
3182
3176
3183
it ( 'handles recursive definitions in discriminators (gh-13978)' , function ( ) {
3177
3184
const base = new Schema ( {
You can’t perform that action at this time.
0 commit comments