【问题标题】:error("Support for `{where: 'raw query'}` has been removed")error(\"对`{where: \'raw query\'}`的支持已被删除\")
【发布时间】:2022-12-18 00:00:06
【问题描述】:

由于此错误,我的过滤不起作用。 我一年前做过这个,一切正常,但是当我现在打开项目并尝试启动时,发现错误,并且无法正常工作 这是我的代码:

async getAll(req, res) {
        const { descriptionId, locationId } = req.query
        let photos
        if (!descriptionId && !locationId) {
            photos = await Photo.findAll()
        }
        if (descriptionId && !locationId) {
            photos = await Photo.findAll({ where: descriptionId })
        }
        if (!descriptionId && locationId) {
            photos = await Photo.findAll({ where: locationId })
        }
        if (descriptionId && locationId) {
            photos = await Photo.findAll({
                where: { descriptionId, locationId },
            })
        }
        return res.json(photos)
    }

而且我的标题有错误错误。我能做什么,再也看不到这个错误?

我试图在互联网上查找信息,但没有成功。多亏了你,你阅读了这条消息并为你提供帮助!!

【问题讨论】:

标签: node.js reactjs postgresql express sequelize.js


【解决方案1】:

尝试这个

 async getAll(req, res) {
    const { descriptionId, locationId } = req.query
    let photos
    if (!descriptionId && !locationId) {
        photos = await Photo.findAll()
    }
    if (descriptionId && !locationId) {
        photos = await Photo.findAll({ where:{descriptionId} })
    }
    if (!descriptionId && locationId) {
        photos = await Photo.findAll({ where: {locationId} })
    }
    if (descriptionId && locationId) {
        photos = await Photo.findAll({
            where: { descriptionId, locationId },
        })
    }
    return res.json(photos)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-06-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多