Handle possible undefined id

This commit is contained in:
Laurent Villeneuve 2015-08-17 13:48:26 -04:00
parent 9363354e0f
commit 94ff275bbc
1 changed files with 2 additions and 2 deletions

View File

@ -2268,7 +2268,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
if (!params.polymorphic) {
modelFrom.validate(propertyName, function(err) {
var embeddedList = this[propertyName] || [];
var ids = embeddedList.map(function(m) { return m[idName].toString(); }); // mongodb
var ids = embeddedList.map(function(m) { return m[idName] && m[idName].toString(); }); // mongodb
var uniqueIds = ids.filter(function(id, pos) {
return ids.indexOf(id) === pos;
});
@ -2869,7 +2869,7 @@ RelationDefinition.referencesMany = function referencesMany(modelFrom, modelTo,
});
modelFrom.validate(relationName, function(err) {
var ids = (this[fk] || []).map(function (id) {return id.toString(); }); // mongodb
var ids = (this[fk] || []).map(function (id) {return id && id.toString(); }); // mongodb
var uniqueIds = ids.filter(function(id, pos) {
return ids.indexOf(id) === pos;
});