简体   繁体   中英

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:

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

I launched the application, and went to the address indicated. I questioned the GET method, having this error:

"stack": "Error: ER_BAD_FIELD_ERROR: Unknown column 'id' in 'field list'\\n

but I do not have an ID field in my table. 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.

Assuming for your model, property mov_id is the id. Define so in the model by adding id: true line: Reference

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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