From 20e5d3c01b8dc925ae66d0c37eae18256abf742f 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 f0621046..670a5dfd 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -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] || []; diff --git a/test/relations.test.js b/test/relations.test.js index 37b59c7a..e0788a7e 100644 --- a/test/relations.test.js +++ b/test/relations.test.js @@ -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); });