问题
How I can inject new models from boot script?
At the moment I have model-config.json where model are configurated, but is it possible to inject those from boot script?
model-config.json
"MyModel": {
"dataSource": "db",
"public": true
}
my-model-bootscript.js
How I can do the same in bootscript?
回答1:
Here is a sample code similar to what we use in our project to create models from a boot script:
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);
来源:https://stackoverflow.com/questions/54506792/loopback-inject-new-models-from-boot-script