我想运行一个使用主键对结果进行排序的查询,并限制返回结果的数量。例如:
return Things.findAll({
attributes: [
'id',
'status',
'otherField'
],
limit: 2,
order: [['id', 'DESC']]
})
构建查询时,会生成以下 SQL 语句:
... ORDER BY [Source].[id] DESC, [id] OFFSET 0 ROWS FETCH NEXT 2 ROWS ONLY
Because id
是主键,排序参数也是id
我收到以下错误:
'A column has been specified more than once in the order by list. Columns in the order by list must be unique.'
我正在使用sequelize 3.30.4和繁琐的2.0.0连接到Microsoft SQL server 2017。
谢谢。
订单数组应包含数组/元组。尝试这个:
return Things.findAll({
attributes: [
'id',
'status',
'otherField'
],
limit: 2,
order: [
['id', 'DESC']
]
})
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)