Search code examples
node.jsloopback

nodejs, Loopback change model name / table name (with mysql)


use Loopback(nodejs) with mysql.

I want to change the model name/table name. (different name)

I don't want to see table name (in API URL)

table name = 'super_member'

model name = 'member'

api url = '/api/member/';

what can I do?


Solution

  • You can customize models by adding a mysql property on the model and/or on the properties :

    {
      "name": "yourModelName",
      "base": "PersistedModel",
      "idInjection": false,
      "mysql": {
        "schema": "YOUR DATABASE NAME",
        "table": "YOUR MYSQL TABLE NAME"
      },
      "properties": {
        "PropertyOne": {
          "type": "Number"
          "required": true,
          "mysql": {
            "columnName": "YOUR MYSQL COLUMN NAME",
            "dataType": "int",
            "dataLength": null,
            "dataPrecision": 10,
            "dataScale": 0,
            "nullable": "N"
          },
          "_selectable": false
        }
      },
      "validations": [],
      "relations": {},
      "acls": [],
      "methods": {}
    }