Loopback inject new models from boot script

大兔子大兔子 提交于 2019-12-11 04:13:36

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!