gpt4 book ai didi

include - 如何使用 order By 和包含在 sequelize js 中

转载 作者:行者123 更新时间:2023-12-03 22:38:27 25 4
gpt4 key购买 nike

我正在尝试使用在运行时在查询和别名中计算的列获取结果

distance



这是我的查询
User.findAll({
include: [{
model: Address,
attributes: ['col1',
[Sequelize.literal("6371 acos(cos(radians(122)) cos(radians(latitude)) cos(radians(122) - radians(longitude)) + sin(radians(6661)) sin(radians(latitude)))"), 'distance']
],
}],
order: [Sequelize.literal("Address.distance"), 'DESC']
});

但它返回一个错误

unknown column Address.distance



我也试过这个
User.findAll({
include: [{
model: Address,
attributes: ['col1',
[Sequelize.literal("6371 acos(cos(radians(122)) cos(radians(latitude)) cos(radians(122) - radians(longitude)) + sin(radians(6661)) sin(radians(latitude)))"), 'distance']
],
}],
order: ["distance", 'DESC']
});

但它给出了同样的错误:

unknown column distance



任何人都可以帮助解决这个问题。
提前致谢

最佳答案

尝试明确指定您想要排序的模型。

User.findAll({
...
order: [ [ Address, 'distance', 'DESC' ] ]
});

关于include - 如何使用 order By 和包含在 sequelize js 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54483929/

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