From 6f815526b0f3136f9ecfdf15018890f6c104b883 Mon Sep 17 00:00:00 2001 From: Fabien Franzen Date: Tue, 19 Aug 2014 22:15:30 +0200 Subject: [PATCH] Validate embedded models by default --- lib/relation-definition.js | 4 ++-- test/relations.test.js | 5 ++--- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/relation-definition.js b/lib/relation-definition.js index 63592e8c..b0378a4c 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -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] || []; diff --git a/test/relations.test.js b/test/relations.test.js index 564102cb..cf875581 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -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); });