From a700eae2d4265a36f1230d43a2c9084230a3a8c7 Mon Sep 17 00:00:00 2001 From: Typicode Date: Fri, 17 Apr 2015 07:08:01 +0200 Subject: [PATCH] Enhance foreign key detection --- src/utils.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/utils.js b/src/utils.js index ed4807f..de6b19f 100644 --- a/src/utils.js +++ b/src/utils.js @@ -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 }) + } } } })