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

一世执手 提交于 2019-12-13 02:13:17

问题


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?


回答1:


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": {}
}


来源:https://stackoverflow.com/questions/54002985/nodejs-loopback-change-model-name-table-name-with-mysql

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!