Skip to content

Commit

Permalink
Merge pull request #9886 from Automattic/gh9884
Browse files Browse the repository at this point in the history
actually updated all the isSelected to $__isSelected
  • Loading branch information
vkarpov15 authored Feb 1, 2021
2 parents 71e6b58 + 40b2b40 commit 5c7d047
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 9 deletions.
12 changes: 6 additions & 6 deletions lib/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ function init(self, obj, doc, opts, prefix) {
// Should still work if not a model-level discriminator, but should not be
// necessary. This is *only* to catch the case where we queried using the
// base model and the discriminated model has a projection
if (self.schema.$isRootDiscriminator && !self.isSelected(path)) {
if (self.schema.$isRootDiscriminator && !self.$__isSelected(path)) {
return;
}

Expand Down Expand Up @@ -1139,7 +1139,7 @@ Document.prototype.$set = function $set(path, val, type, options) {
// traverse the element ({nested: null})` is not likely. If user gets
// that error, its their fault for now. We should reconsider disallowing
// modifying not selected paths for 6.x
if (!this.isSelected(curPath)) {
if (!this.$__isSelected(curPath)) {
this.unmarkModified(curPath);
}
cur = this.$__getValue(curPath);
Expand Down Expand Up @@ -1420,7 +1420,7 @@ Document.prototype.$__shouldModify = function(pathToMark, path, constructing, pa
return false;
}

if (val === void 0 && !this.isSelected(path)) {
if (val === void 0 && !this.$__isSelected(path)) {
// when a path is not selected in a query, its initial
// value will be undefined.
return true;
Expand Down Expand Up @@ -2061,7 +2061,7 @@ Document.prototype.isSelected = function isSelected(path) {
path = path.split(' ');
}
if (Array.isArray(path)) {
return path.some(p => this.isSelected(p));
return path.some(p => this.$__isSelected(p));
}

const paths = Object.keys(this.$__.selected);
Expand Down Expand Up @@ -2259,7 +2259,7 @@ function _getPathsToValidate(doc) {

// only validate required fields when necessary
let paths = new Set(Object.keys(doc.$__.activePaths.states.require).filter(function(path) {
if (!doc.isSelected(path) && !doc.isModified(path)) {
if (!doc.$__isSelected(path) && !doc.isModified(path)) {
return false;
}
if (path in doc.$__.cachedRequired) {
Expand Down Expand Up @@ -3568,7 +3568,7 @@ function applyGetters(self, json, options) {
let part;
cur = self._doc;

if (!self.isSelected(path)) {
if (!self.$__isSelected(path)) {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/helpers/timestamps/setupTimestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ module.exports = function setupTimestamps(schema, timestamps) {
(this.ownerDocument ? this.ownerDocument() : this).constructor.base.now();
const auto_id = this._id && this._id.auto;

if (!skipCreatedAt && createdAt && !this.get(createdAt) && this.isSelected(createdAt)) {
if (!skipCreatedAt && createdAt && !this.get(createdAt) && this.$__isSelected(createdAt)) {
this.$set(createdAt, auto_id ? this._id.getTimestamp() : defaultTimestamp);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -823,7 +823,7 @@ Model.prototype.$__version = function(where, delta) {
// there is no way to select the correct version. we could fail
// fast here and force them to include the versionKey but
// thats a bit intrusive. can we do this automatically?
if (!this.isSelected(key)) {
if (!this.$__isSelected(key)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lib/types/embedded.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ EmbeddedDocument.prototype.markModified = function(path) {
}

const pathToCheck = this.__parentArray.$path() + '.0.' + path;
if (this.isNew && this.ownerDocument().isSelected(pathToCheck)) {
if (this.isNew && this.ownerDocument().$__isSelected(pathToCheck)) {
// Mark the WHOLE parent array as modified
// if this is a new document (i.e., we are initializing
// a document),
Expand Down
53 changes: 53 additions & 0 deletions test/document.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -9878,4 +9878,57 @@ describe('document', function() {
assert.equal(ss.nested[0].toHexString(), updatedElID);
});
});
it('gh9884', function() {
return co(function*() {

const obi = new Schema({
eType: {
type: String,
required: true,
uppercase: true
},
eOrigin: {
type: String,
required: true
},
eIds: [
{
type: String
}
]
}, { _id: false });

const schema = new Schema({
name: String,
description: String,
isSelected: {
type: Boolean,
default: false
},
wan: {
type: [obi],
default: undefined,
required: true
}
});

const newDoc = {
name: 'name',
description: 'new desc',
isSelected: true,
wan: [
{
eType: 'X',
eOrigin: 'Y',
eIds: ['Y', 'Z']
}
]
};

const Model = db.model('Test', schema);
yield Model.create(newDoc);
const doc = yield Model.findOne();
assert.ok(doc);
});
});
});

0 comments on commit 5c7d047

Please sign in to comment.