羽毛 - PATCH 时 where 子句中的未知列
Feathers - Unknown column in where clause when PATCH
我正在为 mysql 数据库使用 Sequelize。
当我使用 Postman 的 Find
函数时,它 returns:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"id": "1",
"latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e91177"
}
]
}
然后我尝试使用Patch
修改Postman中的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": {}
}
我不知道为什么会发生这种情况,因为我检查并确认 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;
};
在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
}
...
...
};
我正在为 mysql 数据库使用 Sequelize。
当我使用 Postman 的 Find
函数时,它 returns:
{
"total": 1,
"limit": 10,
"skip": 0,
"data": [
{
"id": "1",
"latestNewsId": "f8b53a32-b729-41f8-9888-df2b71e91177"
}
]
}
然后我尝试使用Patch
修改Postman中的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": {}
}
我不知道为什么会发生这种情况,因为我检查并确认 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;
};
在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
}
...
...
};