我有两个ID数组:
placeids = [22,14]
然后我有了这个问题:
models.Places.findAll({
where: {
id: {in: [ placeids ]}
}
}).then(function (places) {
response(places).code(200);
}, function (rejectedPromiseError) {
response(rejectedPromiseError).code(401);
});
我希望结果返回准确的记录,我请求它们的方式,在我的案例22和14中。
Sequelize返回它们,但它以降序命令它们。所以在我的情况下,它返回14和22。
我该如何解决这个问题?
答案 0 :(得分:1)
您可以传递sequelize
order
参数:
models.Places.findAll({
where: {
id: {in: [placeids]}
},
order: 'id DESC'
});
或者,您可以手动进行订购:
.then(function (places) {
places.sort(function (x, y) {
return placeids.indexOf(x.id) > placeids.indexOf(y.id)
});
return places;
});