mirror of
https://github.com/typicode/json-server.git
synced 2025-07-28 12:43:18 +08:00
Enhance foreign key detection
This commit is contained in:
@ -50,11 +50,15 @@ function getRemovable(db) {
|
||||
_(doc).each(function(value, key) {
|
||||
if (/Id$/.test(key)) {
|
||||
var refName = _.pluralize(key.slice(0, - 2))
|
||||
// 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 })
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
})
|
||||
|
Reference in New Issue
Block a user