Loopbackjs 删除环回3中的基本模型关系
我在尝试删除关系时遇到了一点麻烦 来自使用另一个自定义模型作为基础的模型。假设: 设置 当我查看Loopbackjs 删除环回3中的基本模型关系,loopbackjs,Loopbackjs,我在尝试删除关系时遇到了一点麻烦 来自使用另一个自定义模型作为基础的模型。假设: 设置 当我查看特殊项目模型时,我发现parentId仍然存在,并且 它甚至出现在关系中 在loopback 3中,从子模型中删除父模型关系的正确方法是什么?我觉得现在发布这个问题有点傻,因为发布后不久我找到了一种解决方法 我在这里发布我的解决方案,如果有人可以查看,我将不胜感激: 创建一个名为clear relations.js的模块 在其内部使用以下代码位- 如果您的模型还没有.js文件,请创建一个,然后使用以下
特殊项目
模型时,我发现parentId仍然存在,并且
它甚至出现在关系中
在loopback 3中,从子模型中删除父模型关系的正确方法是什么?我觉得现在发布这个问题有点傻,因为发布后不久我找到了一种解决方法 我在这里发布我的解决方案,如果有人可以查看,我将不胜感激:
clear relations.js的模块
// Item Model, item.json
...
"relations": {
"parent": {"type": "belongsTo", "model": "Holder"}
}
...
// Special Item Model, item.json
...
"base": "Item",
"excludeBaseProperties": ["parentId"],
...
"relations": {}
...
'use strict';
module.exports = function(Model) {
// Get the attribute names of the inherited relations
// and then explicitly delete them
Object.keys(Model.settings.relations).forEach(relation => {
delete Model.settings.relations[relation];
});
}
const ClearRelations = require("path/to/clear-relations.js");
module.exports = function(MyModel) {
ClearRelations(MyModel);
}