如何从启动脚本中注入新模型?
目前我有model-config.json,其中配置了模型,但是可以从启动脚本中注入吗?
model-config.json
"MyModel": {
"dataSource": "db",
"public": true
}
my-model-bootscript.js
How I can do the same in bootscript?
答案 0 :(得分:1)
这是一个示例代码,类似于我们在项目中使用引导脚本创建模型的代码:
const modelDefinition = {
name: "ModelName",
properties: {
modelProperty1: {
type: "string", required: true,
},
},
hidden: ["id"],
mixins: {
},
dataSource: "memory", // or one of your datasources
};
// here we dynamically create create model
loopback.createModel(modelDefinition);