Skip to content

Commit a700eae

Browse files
committed
Enhance foreign key detection
1 parent 73c206e commit a700eae

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/utils.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,13 @@ function getRemovable(db) {
5050
_(doc).each(function(value, key) {
5151
if (/Id$/.test(key)) {
5252
var refName = _.pluralize(key.slice(0, - 2))
53-
var ref = _.findWhere(db[refName], {id: value})
54-
if (_.isUndefined(ref)) {
55-
removable.push({ name: collName, id: doc.id })
53+
// Test if table exists
54+
if (db[refName]) {
55+
// Test if references is defined in table
56+
var ref = _.findWhere(db[refName], {id: value})
57+
if (_.isUndefined(ref)) {
58+
removable.push({ name: collName, id: doc.id })
59+
}
5660
}
5761
}
5862
})

0 commit comments

Comments
 (0)