Validate embedded models by default

This commit is contained in:
Fabien Franzen 2014-08-19 22:15:30 +02:00
parent 7c901af6d9
commit 6f815526b0
2 changed files with 4 additions and 5 deletions

View File

@ -1602,7 +1602,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) {
@ -1775,7 +1775,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

@ -1337,8 +1337,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
});
});
@ -1640,7 +1639,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);
});