Loopback: How to change the name of a model?

1.5k views Asked by At

I have a model with name "aaa_bbb", I want to change the name to aaa-bbb, I would like to know how I can achieve that? Or can I just change the name directly in my model json file? Here is the my current model.json file.

{
  "name": "aaa_bbb",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    ...
  },
  "acls": [],
  "methods": []
}
1

There are 1 answers

0
superkhau On

Typically there are 3 steps:

1 - Change the model name in server/model-config.js

{
  ...
  "aaa_bbb": { // change this to "aaa-bbb"
    "dataSource": "db",
    "public": true
  }
}

2 - Change the model name in common/models/aaa-bbb.json:

{
  "name": "aaa_bbb", // change this to "aaa-bbb"
  "base": "PersistedModel",
  ...
}

3 - Change the model name in `commmon/models/aaa-bbb.js:

module.exports = function(AaaBbb) { // usually you change this...

};

...however, in your case AaaBbb doesn't change, so you do not need to perform step 3. LoopBack automatically removes the _ or - from the model name and UpperCamelCases the model name during scaffolding. This means BOTH aaa_bbb and aaa-bbb would output AaaBbb.