Validate embedded models by default

This commit is contained in:
Fabien Franzen 2014-08-19 22:15:30 +02:00 committed by Raymond Feng
parent 1ec5357a6c
commit 20e5d3c01b
2 changed files with 4 additions and 5 deletions

View File

@ -1601,7 +1601,7 @@ RelationDefinition.embedsOne = function (modelFrom, modelTo, params) {
modelFrom.dataSource.defineProperty(modelFrom.modelName, propertyName, opts);
// validate the embedded instance
if (definition.options.validate) {
if (definition.options.validate !== false) {
modelFrom.validate(relationName, function(err) {
var inst = this[propertyName];
if (inst instanceof modelTo) {
@ -1774,7 +1774,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
}
// validate all embedded items
if (definition.options.validate) {
if (definition.options.validate !== false) {
modelFrom.validate(propertyName, function(err) {
var self = this;
var embeddedList = this[propertyName] || [];

View File

@ -1339,8 +1339,7 @@ describe('relations', function () {
it('can be declared using embedsOne method', function () {
Person.embedsOne(Passport, {
default: {name: 'Anonymous'}, // a bit contrived
options: {validate: true}
default: {name: 'Anonymous'} // a bit contrived
});
});
@ -1642,7 +1641,7 @@ describe('relations', function () {
});
it('can be declared', function (done) {
Person.embedsMany(Address, { options: { autoId: false, validate: true } });
Person.embedsMany(Address, { options: { autoId: false } });
db.automigrate(done);
});