user2114916
user2114916

Reputation: 31

LoopBack - splitting model-config.json

Having many models would like for maintenance purposes to split the model-config.json. How to do this?

Upvotes: 1

Views: 789

Answers (1)

stujo
stujo

Reputation: 2109

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

Upvotes: 2

Related Questions