HTML PUT sails-filemaker

Kei*_*son 2 filemaker sails.js

我刚刚开始使用sails-filemaker与文件制作服务器通信.我喜欢它:-)我正在寻找一种方法来处理HTML PUT请求来更新记录.

模型是

    /**
    * LocalityFilemaker.js
    *
    * @description :: Suburbs (locality) in the evolution database.
    * @docs        :: http://sailsjs.org/#!documentation/models
    */

    module.exports = {

        connection: 'filemaker', 
        tableName: 'locality-sails-layout',

      attributes: {
            id: {
                type: 'integer',
                primaryKey: true,
                autoIncrement: true
            }, 
            suburb: {
                type: 'string'
            },
            state: {
                type: 'string'
            },
            postcode: {
                type: 'string'
            }

      }

    };
Run Code Online (Sandbox Code Playgroud)

当我打电话给{{url}}/localityFilemaker/12600时,我得到了回复.

    {
      "id": 12600,
      "suburb": "LARGS BAY",
      "state": "SA",
      "postcode": "5016",
      "modid": "3",
      "recid": "29500",
      "createdAt": "1970-01-01T00:00:00.000Z",
      "updatedAt": "1970-01-01T00:00:00.000Z"
    }
Run Code Online (Sandbox Code Playgroud)

当我向{{url}}/localityFilemaker/12600或{{url}}/localityFilemaker调用put时

    {
      "id": 12600,
      "suburb": "LARGS BAY.",
      "state": "SA",
      "postcode": "5016",
      "recid": "29500"
    }
Run Code Online (Sandbox Code Playgroud)

我收到400 Bad请求.使用PUT HTML请求使用sails-filemaker更新记录的最佳方法是什么?

Nic*_*ant 5

如果我错了,我希望托德会纠正我.看起来"recid"是一个FileMaker内部记录ID,你的put正在尝试更新它.从你的put JSON中删除"recid",它应该可以工作.

  • 是的nicolai.kant是对的.它是一个内部ID.sails-filemaker不使用它来查找要更新的记录,因为这不是标准的Sails/Waterline行为或非常RESTFUL它使用模型定义的主键.应该注意,这确实需要对DB进行两次请求.第一个找到recid,下一个使用recid来更新记录. (2认同)
  • 还有一点需要注意.modid可以传回来.如果确实将其传回,则必须与服务器记录的modid匹配,否则请求将失败.这为您提供了一种避免覆盖服务器上发生的更改的方法.它是一种简单的并发控制形式.大多数时候你可以放弃modid,但如果你需要额外的concurency控件,你就可以了 (2认同)