Validate embedded models by default
This commit is contained in:
parent
1ec5357a6c
commit
20e5d3c01b
|
@ -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] || [];
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue