Search code examples
mysqlnode.jssequelize.jsfeathersjs

Feathers - Unknown column in where clause when PATCH


I am using Sequelize for the mysql database.

When I use Find function by Postman, it returns:

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

Then I tried to modify the latestNewsId in Postman using Patch, by id.

PATCH localhost:3030/latest_news_featured/1

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

This is the error occuring then:

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

I don't know why would this happens because I checked and confirm id and latestNewsId exist in database.

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


Solution

  • In the latest-news-featured.class, when I comment this.options = options || {};, it works instantly.

    I am not sure the reason, so I leave this here and hope it can help others with the same problem.

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