Require unique ids for embedded items

This commit is contained in:
Fabien Franzen 2014-07-27 17:30:10 +02:00
parent 43e11af942
commit e1ecb4b95f
1 changed files with 13 additions and 15 deletions

View File

@ -1406,8 +1406,7 @@ RelationDefinition.embedsMany = function hasMany(modelFrom, modelTo, params) {
type: [modelTo], default: function() { return []; } type: [modelTo], default: function() { return []; }
}); });
// require explicit/unique ids unless autoId === true // unique id is required
if (definition.options.autoId === false) {
modelTo.validatesPresenceOf(idName); modelTo.validatesPresenceOf(idName);
modelFrom.validate(relationName, function(err) { modelFrom.validate(relationName, function(err) {
var embeddedList = this[relationName] || []; var embeddedList = this[relationName] || [];
@ -1420,7 +1419,6 @@ RelationDefinition.embedsMany = function hasMany(modelFrom, modelTo, params) {
err(false); err(false);
} }
}, { code: 'uniqueness' }) }, { code: 'uniqueness' })
}
// validate all embedded items // validate all embedded items
if (definition.options.validate) { if (definition.options.validate) {