Skip to content

Commit

Permalink
Avoids saving an instance if a property is null and is marked as requ…
Browse files Browse the repository at this point in the history
…ired (#142)
  • Loading branch information
dresende committed May 2, 2013
1 parent 079fe7f commit 19492db
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions lib/Instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ function Instance(opts) {
if (!opts.properties.hasOwnProperty(k)) continue;
if (opts.data[k] == null && opts.properties[k].hasOwnProperty("defaultValue")) {
opts.data[k] = opts.properties[k].defaultValue;
} else if (opts.properties[k].required && opts.data[k] == null) {
var err = new Error("required");
err.field = k;
err.value = opts.data[k];

Hook.trigger(instance, opts.hooks.afterSave, false);
if (typeof cb == "function") {
cb(err, instance);
}
return;
}
}

Expand Down

0 comments on commit 19492db

Please sign in to comment.