Having many models would like for maintenance purposes to split the model-config.json. How to do this?
Asked
Active
Viewed 778 times
1 Answers
2
Looking at the code it looks like the loader will use the options.models from the options passed into the boot call (which is usually in server.js)
Line 39 in /node_modules/loopback-boot/lib/compiler.js
var modelsConfig = options.models ||
ConfigLoader.loadModels(modelsRootDir, env);
assertIsValidModelConfig(modelsConfig);
So you can try something like this:
var options = {
appRootDir: __dirname,
models: {
"_meta": {
"sources": [
"loopback/common/models",
"loopback/server/models",
"../common/models",
"./models",
"../node_modules/loopback-component-passport/lib/models"
]
},
"user": {
"dataSource": "db",
"public": false
}
}
};
boot(app, options);
That should skip loading the model-config.json file entirely
If that works then all you have to do is break your file up and load it yourself into the option.models property before you call boot and your problem is solved

stujo
- 2,089
- 24
- 29
-
Thank you for the answer! I would like to avoid touching the loopback distribution code to prevent for later maintenance issues but will definitly try this one if no other alternative. – user2114916 Jan 25 '15 at 12:16
-
this is in your main app.js you can pass the configuration into the boot function call, no changes to distribution at all – stujo Jan 29 '15 at 16:11
-
This was very helpful. Could not find any other way to load a different model configuration depending on the environment variable. – Ruslan Kurkebayev Sep 05 '18 at 12:33