Validate embedded models by default
This commit is contained in:
parent
7c901af6d9
commit
6f815526b0
|
@ -1602,7 +1602,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) {
|
||||||
|
@ -1775,7 +1775,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] || [];
|
||||||
|
|
|
@ -1337,8 +1337,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}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1640,7 +1639,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