gpt4 book ai didi

sql-server - TypeError : identifier. 替换不是函数 - Sequelize

转载 作者:行者123 更新时间:2023-12-03 22:32:46 26 4
gpt4 key购买 nike

我有两个表 StudyGroupStudents ,它们之间是多对多关系,由交集表 StudentGroups 解决。我试图找出每个 StudyGroup 有多少学生。下面是我的代码

    router.route("/studocu/students/count").get((req, res) => {
GrupDeStudiu.findAll({
attributes: ['id', 'Nume'],
include: {
model: Student
}
}).then(response => res.json(response))
.catch(err => console.error(err))
})
每次运行它时,我都会收到相同的错误 TypeError: identifier.replace is not a function更新 2
router.route("/studocu/students/count").get((req, res) => {
GrupDeStudiu.findAll({
attributes: ['id', 'Nume'],
include: {
model: Student
through: {
attributes: [[seq.fn('COUNT', seq.col('id')), 'Numar Studenti']]
}
},
group: ['Grup_De_Studiu.id', 'Grup_De_Studiu.Nume']
}).then(response => res.json(response))
.catch(err => console.error(err))
})

最佳答案

我想你应该像这样更正 attributes 定义:

attributes: [[seq.fn('count', seq.col('id')), 'Numar Studenti']]
因为 [seq.fn('count', seq.col('id')), 'Numar Studenti'] 是单个属性的定义,而属性是数组字符串和/或此类属性数组或具有 includeexclude 键的对象。

关于sql-server - TypeError : identifier. 替换不是函数 - Sequelize,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65359162/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com