Create Model.json file programmatically

32 views
Skip to first unread message

Michael Inthirath

unread,
Jan 17, 2017, 1:12:27 PM1/17/17
to LoopbackJS
Hello,

New to Loopback and am scratching my head on how to create a Model definition programmatically and have it generate its model.json file.
I have looked at Instance Instrospection , but I simply want to create a model from already having the definition and not having an instance yet.
 
I have this in my code:

   
var newModel = db.createModel(contentType.name, properties, { "base": "PersistedModel", "idInjection": true });
    newModel
.setup();
    app
.model(newModel);

Which creates the model and it shows up in API explorer and all, but it doesn't create the model.json file. 
  1. Is this the proper way to create a Model definition dynamically?
  2. Is there a way to generate the model.json file or would i have to build that manually? 
Thanks. 
 
 

sim...@ca.ibm.com

unread,
Jan 19, 2017, 3:02:40 PM1/19/17
to LoopbackJS
Does `slc loopback:model` work for you?

Michael Inthirath

unread,
Jan 20, 2017, 1:07:53 PM1/20/17
to LoopbackJS
Yes through the command line, but is there a built-in API command to create a model.json file from a Model or Model Definition?

sim...@ca.ibm.com

unread,
Jan 20, 2017, 5:06:30 PM1/20/17
to LoopbackJS
Not OOB, but you can use a combination of discovery + require('fs') to do this -- see http://loopback.io/doc/en/lb2/Discovering-models-from-relational-databases.html
Reply all
Reply to author
Forward
0 new messages