首页 > 解决方案 > Feathers - PATCH 时 where 子句中的未知列

问题描述

我正在为 mysql 数据库使用 Sequelize。

当我使用FindPostman 的函数时,它返回:

{
    "total": 1,
    "limit": 10,
    "skip": 0,
    "data": [
        {
            "id": "1",
            "latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e91177"
        }
    ]
}

然后我尝试使用, by修改latestNewsIdPostman 中的.Patchid

PATCH localhost:3030/latest_news_featured/1

Body:
{
     "latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e12345"
}

这是发生的错误:

{
    "name": "GeneralError",
    "message": "Unknown column 'latest_news_featured.undefined' in 'where clause'",
    "code": 500,
    "className": "general-error",
    "errors": {}
}

我不知道为什么会发生这种情况,因为我检查并确认id并存latestNewsId在于数据库中。

latest_news_featured.models.js

const Sequelize = require('sequelize');
const DataTypes = Sequelize.DataTypes;

module.exports = function (app) {
  const sequelizeClient = app.get('sequelizeClient');
  const latestNewsFeatured = sequelizeClient.define('latest_news_featured', {
    id: {
      type: DataTypes.STRING,
      allowNull: false,
      defaultValue: 1,
      primaryKey: true
    },
    latestNewsId: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      allowNull: false,
    }
  }, {
    hooks: {
      beforeCount(options) {
        options.raw = true;
      }
    }
  });

  latestNewsFeatured.associate = function (models) { };
  return latestNewsFeatured;
};

标签: mysqlnode.jssequelize.jsfeathersjs

解决方案


在 中latest-news-featured.class,当我发表评论时this.options = options || {};,它会立即生效。

我不确定原因,所以我把它留在这里,希望它可以帮助其他有同样问题的人。

最新新闻-featured.class.js

const { Service } = require('feathers-sequelize');

exports.LatestNewsFeatured = class LatestNewsFeatured extends Service {
  
    constructor (options,app) {
        super(options, app);
        this.app = app;
        //this.options = options || {};   //Comment this line to make it works
    }
    ...

    ...
};


推荐阅读