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);
|
modelFrom.dataSource.defineProperty(modelFrom.modelName, propertyName, opts);
|
||||||
|
|
||||||
// validate the embedded instance
|
// validate the embedded instance
|
||||||
if (definition.options.validate) {
|
if (definition.options.validate !== false) {
|
||||||
modelFrom.validate(relationName, function(err) {
|
modelFrom.validate(relationName, function(err) {
|
||||||
var inst = this[propertyName];
|
var inst = this[propertyName];
|
||||||
if (inst instanceof modelTo) {
|
if (inst instanceof modelTo) {
|
||||||
|
@ -1774,7 +1774,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
// validate all embedded items
|
// validate all embedded items
|
||||||
if (definition.options.validate) {
|
if (definition.options.validate !== false) {
|
||||||
modelFrom.validate(propertyName, function(err) {
|
modelFrom.validate(propertyName, function(err) {
|
||||||
var self = this;
|
var self = this;
|
||||||
var embeddedList = this[propertyName] || [];
|
var embeddedList = this[propertyName] || [];
|
||||||
|
|
|
@ -1339,8 +1339,7 @@ describe('relations', function () {
|
||||||
|
|
||||||
it('can be declared using embedsOne method', function () {
|
it('can be declared using embedsOne method', function () {
|
||||||
Person.embedsOne(Passport, {
|
Person.embedsOne(Passport, {
|
||||||
default: {name: 'Anonymous'}, // a bit contrived
|
default: {name: 'Anonymous'} // a bit contrived
|
||||||
options: {validate: true}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1642,7 +1641,7 @@ describe('relations', function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can be declared', function (done) {
|
it('can be declared', function (done) {
|
||||||
Person.embedsMany(Address, { options: { autoId: false, validate: true } });
|
Person.embedsMany(Address, { options: { autoId: false } });
|
||||||
db.automigrate(done);
|
db.automigrate(done);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue