Handle possible undefined id
This commit is contained in:
parent
9363354e0f
commit
94ff275bbc
|
@ -2268,7 +2268,7 @@ RelationDefinition.embedsMany = function embedsMany(modelFrom, modelTo, params)
|
||||||
if (!params.polymorphic) {
|
if (!params.polymorphic) {
|
||||||
modelFrom.validate(propertyName, function(err) {
|
modelFrom.validate(propertyName, function(err) {
|
||||||
var embeddedList = this[propertyName] || [];
|
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) {
|
var uniqueIds = ids.filter(function(id, pos) {
|
||||||
return ids.indexOf(id) === pos;
|
return ids.indexOf(id) === pos;
|
||||||
});
|
});
|
||||||
|
@ -2869,7 +2869,7 @@ RelationDefinition.referencesMany = function referencesMany(modelFrom, modelTo,
|
||||||
});
|
});
|
||||||
|
|
||||||
modelFrom.validate(relationName, function(err) {
|
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) {
|
var uniqueIds = ids.filter(function(id, pos) {
|
||||||
return ids.indexOf(id) === pos;
|
return ids.indexOf(id) === pos;
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue