Enhance foreign key detection

This commit is contained in:
Typicode
2015-04-17 07:08:01 +02:00
parent 73c206e79a
commit a700eae2d4

View File

@ -50,9 +50,13 @@ function getRemovable(db) {
_(doc).each(function(value, key) {
if (/Id$/.test(key)) {
var refName = _.pluralize(key.slice(0, - 2))
var ref = _.findWhere(db[refName], {id: value})
if (_.isUndefined(ref)) {
removable.push({ name: collName, id: doc.id })
// Test if table exists
if (db[refName]) {
// Test if references is defined in table
var ref = _.findWhere(db[refName], {id: value})
if (_.isUndefined(ref)) {
removable.push({ name: collName, id: doc.id })
}
}
}
})