Skip to content

Commit

Permalink
Merge branch 'master' into testFix
Browse files Browse the repository at this point in the history
  • Loading branch information
fishcharlie committed Mar 20, 2020
2 parents 2e732ac + 7ec56cf commit b6a50f9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/Document.js
Expand Up @@ -159,7 +159,8 @@ function DocumentCarrier(model) {
utils.object.set(returnObject, key, undefined);
} else {
const defaultValue = await model.schema.defaultCheck(key, value, settings);
if (defaultValue) {
const isDefaultValueUndefined = typeof defaultValue === "undefined" || defaultValue === null;
if (!isDefaultValueUndefined) {
const newObject = mainCheck({}, key, defaultValue);
utils.object.set(returnObject, key, utils.object.get(newObject, key));
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Schema.js
Expand Up @@ -79,7 +79,8 @@ Schema.prototype.defaultCheck = async function(key, value, settings) {
const isValueUndefined = typeof value === "undefined" || value === null;
if ((settings.defaults && isValueUndefined) || (settings.forceDefault && await this.getAttributeSettingValue("forceDefault", key))) {
const defaultValue = await this.getAttributeSettingValue("default", key);
if (defaultValue) {
const isDefaultValueUndefined = typeof defaultValue === "undefined" || defaultValue === null;
if (!isDefaultValueUndefined) {
return defaultValue;
}
}
Expand Down
5 changes: 5 additions & 0 deletions test/Document.js
Expand Up @@ -1344,6 +1344,11 @@ describe("Document", () => {
"output": {"id": "id"},
"schema": {"id": {"type": String, "default": async () => "id"}}
},
{
"input": [{}, {"defaults": true}],
"output": {"id": 0},
"schema": {"id": {"type": Number, "default": 0}}
},
{
"input": [{"id": "test"}, {"validate": true}],
"error": new Error.ValidationError("id with a value of test had a validation error when trying to save the document"),
Expand Down

0 comments on commit b6a50f9

Please sign in to comment.