【问题标题】:Feathers - Unknown column in where clause when PATCHFeathers - PATCH 时 where 子句中的未知列
【发布时间】:2021-05-31 11:38:45
【问题描述】:

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

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

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

然后我尝试在 Postman 中使用 Patch 修改 latestNewsId,通过 id

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

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

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;
};

【问题讨论】:

  • 显示您的更新查询

标签: mysql node.js sequelize.js feathersjs


【解决方案1】:

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

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

latest-news-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
    }
    ...

    ...
};

【讨论】:

    猜你喜欢
    • 2011-06-03
    • 1970-01-01
    • 2021-09-19
    • 2020-06-28
    • 2021-07-02
    • 2019-08-14
    • 2013-07-18
    • 2016-10-04
    相关资源
    最近更新 更多