Inverse relation unlink bug by pik · Pull Request #383 · js-data/js-data
ref: #376 Only the last commit is relevant (will rebase out after) but I built from my previous branch since I think the extraction helps readability. Basically JS-Data already goes down the removeInverseRelation pathway when a relation is set to null/undefined so unlinkInverseRecords is strictly unnecessary.
Further the code in unlinkInverseRecords is flawed (or it would only work correctly for hasOne:
utils.set(record, this.getInverse(this.mapper).localField, undefined)
Compare to (removeInverseRelation):
else if (inverseDef.type === hasManyType) { ... utils.remove(children, (child) => child === this || id === utils.get(child, idAttribute))
Unfortunately simply removing removeInverseRelation broke a test in the destroy suite. This is because the hasOne setter() does not clear correctly, so this was updated as well (see below).