以下查询在具有开发版本(next.js 应用程序)的本地环境上工作得很好,但在产品版本(使用 Vercel 部署)上执行时开始为 Payments 表生成一些随机别名。基本上,Sequelize 会使用
as "gs"
为 Payments
表生成查询。
const existingBooking = await BookingRequests.findByPk(id, {
include: [
{ model: SectorBookings, include: [Payments] },
{ model: BookingComments, attributes: ["text"] },
],
});
Payments
和SectorBookings
之间存在多对多关联
SectorBookings.belongsToMany(Payments, {
through: SectorBookingPayments,
foreignKey: "sectorBookingId",
otherKey: "paymentId",
});
Payments.belongsToMany(SectorBookings, {
through: SectorBookingPayments,
foreignKey: "paymentId",
otherKey: "sectorBookingId",
});
我在使用 [email protected] 时遇到类似问题,但如果我使用 [email protected],问题就会消失。
我还没有确切地确定为什么会出现这种情况,但我的直觉是缩小器正在做一些奇怪的事情。