简体   繁体   English

环回和默认排序

[英]Loopback and default sorting

I'm starting to study loopback. 我开始研究环回。 I created my app, and below this model: 我创建了我的应用,并且在此模型下:

{
  "name": "movimenti",
  "plural": "movimenti",
  "base": "PersistedModel",
  "idInjection": true,
  "options": {
    "validateUpsert": true
  },
  "properties": {
    "mov_id": {
      "type": "number",
      "required": true
    },
    "mov_tipo": {
      "type": "string",
      "required": true
    },
    "mov_valore": {
      "type": "number",
      "required": true
    }
  },
  "validations": [],
  "relations": {},
  "acls": [],
  "methods": {}
}

I connected the model to my MySQL DB: 我将模型连接到我的MySQL数据库:

"movimenti": {
    "dataSource": "banca",
    "public": true
}

I launched the application, and went to the address indicated. 我启动了该应用程序,然后转到指示的地址。 I questioned the GET method, having this error: 我质疑GET方法,并出现以下错误:

"stack": "Error: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list'\\n “ stack”:“错误:ER_BAD_FIELD_ERROR:”字段列表“中的未知列'id'\\ n

but I do not have an ID field in my table. 但我的表中没有ID字段。 How can I fix this problem? 我该如何解决这个问题?

Loopback will automatically add an id column if none of the properties of a model is mentioned as id. 如果没有将模型的任何属性作为ID提及,则环回将自动添加id列。

Assuming for your model, property mov_id is the id. 假设对于您的模型,属性mov_id是ID。 Define so in the model by adding id: true line: Reference 在模型中通过添加id: true定义id: true行: 参考

{
  ...
  "properties": {
    "mov_id": {
      "type": "number",
      "required": true,
      "id":true
    },
  ...
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM