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