diff --git a/lib/relation-definition.js b/lib/relation-definition.js index b022072a..719bf637 100644 --- a/lib/relation-definition.js +++ b/lib/relation-definition.js @@ -1406,21 +1406,19 @@ RelationDefinition.embedsMany = function hasMany(modelFrom, modelTo, params) { type: [modelTo], default: function() { return []; } }); - // require explicit/unique ids unless autoId === true - if (definition.options.autoId === false) { - modelTo.validatesPresenceOf(idName); - modelFrom.validate(relationName, function(err) { - var embeddedList = this[relationName] || []; - var ids = embeddedList.map(function(m) { return m[idName]; }); - var uniqueIds = ids.filter(function(id, pos) { - return ids.indexOf(id) === pos; - }); - if (ids.length !== uniqueIds.length) { - this.errors.add(relationName, 'Contains duplicate `' + idName + '`', 'uniqueness'); - err(false); - } - }, { code: 'uniqueness' }) - } + // unique id is required + modelTo.validatesPresenceOf(idName); + modelFrom.validate(relationName, function(err) { + var embeddedList = this[relationName] || []; + var ids = embeddedList.map(function(m) { return m[idName]; }); + var uniqueIds = ids.filter(function(id, pos) { + return ids.indexOf(id) === pos; + }); + if (ids.length !== uniqueIds.length) { + this.errors.add(relationName, 'Contains duplicate `' + idName + '`', 'uniqueness'); + err(false); + } + }, { code: 'uniqueness' }) // validate all embedded items if (definition.options.validate) {