【发布时间】:2018-01-04 08:11:31
【问题描述】:
如何在Bookshelf JS中使用groupBy,这是我的Controller代码。
router.route('/fetchStudentAttendance')
.post(function(req, res) {
StudentAttendance
.query(function (qb){
qb.where('date', '>=', req.body.date);
qb.groupBy("students_id");
})
.where({'class_id': req.body.class_id, 'section_id': req.body.section_id})
.fetchAll({ withRelated: [{'StudentRef':function(qb) {qb.column('id', 'first_name', 'middle_name', 'last_name')}}]})
.then(studentAttendance => {
let content = {
data: studentAttendance,
success: true,
message: 'Record Not Found',
};
return res.send(content);
})
.catch(error => {
let content = {
data: error,
success: false,
message: 'Error while fetching Student Attendance.',
};
return res.send(content);
});
});
当我尝试“groupBy”employee_id 时,它会给出这样的错误。
code:"42703"
file:"parse_relation.c"
length:110
line:"3194"
name:"error"
position:"127"
routine:"check_ungrouped_columns_walker"
severity:"ERROR"
【问题讨论】:
-
你到底想要达到什么目的?
-
除了回复fingeron的评论,你说
I am not able to use groupBy in Bookshelf JS的理由是什么?到目前为止你做了什么来解决你的问题?你看过文档了吗?您发现文档令人困惑/缺乏什么? bookshelfjs.org/#Model-instance-fetchPage 有一个groupBy正在使用的示例。 -
产生错误的查询是什么?
标签: node.js angular knex.js bookshelf.js