Skip to content

Commit

Permalink
Merge pull request #13132 from rdeavila94/gh-12654
Browse files Browse the repository at this point in the history
Merge pull request #12737 from Automattic/vkarpov15/gh-12654
  • Loading branch information
vkarpov15 authored Mar 6, 2023
2 parents e76c41c + d0e149b commit 9dd82be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/helpers/schema/merge.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ module.exports = function merge(s1, s2, skipConflictingPaths) {
s1.virtuals[virtual] = s2.virtuals[virtual].clone();
}

s1._indexes = s1._indexes.concat(s2._indexes || []);
s1.s.hooks.merge(s2.s.hooks, false);
};
10 changes: 10 additions & 0 deletions test/schema.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2401,6 +2401,16 @@ describe('schema', function() {
assert.equal(TurboManSchema.path('year').instance, 'Number');
});

it('copies indexes when calling add() with schema instance (gh-12654)', function() {
const ToySchema = Schema({ name: String });
ToySchema.index({ name: 1 });

const TurboManSchema = Schema();
TurboManSchema.add(ToySchema);

assert.deepStrictEqual(TurboManSchema.indexes(), [[{ name: 1 }, { background: true }]]);
});

describe('gh-8849', function() {
it('treats `select: undefined` as not specifying `select` option', function() {
const userSchema = new Schema({ name: { type: String, select: undefined } });
Expand Down

0 comments on commit 9dd82be

Please sign in to comment.