Sequelize 关联查询的时候 A表的一个字段和B表的一个字段比较的条件该怎么写?

求大神, Sequelize 关联查询的时候 A表的一个字段和B表的一个字段比较的条件该怎么写?

比如我这里 A.currentIndex > B.index 要怎么写

A的 where 的 currentIndex 不知道写才对?

A表和B表

select * from A left join B on A.mesId = B.mesId where A.id = 1 and A.currentIndex > B.index

要实现的sql就是这个,下面是我的写法,但是是错的,求大神

const result = await A.findAll({
where: {id: ticketId, currentIndex: {[Op.gt]: Sequelize.literal(`Bname.index`)}},  //现在这里是不对的写法
attributes: ['id', 'mesId'],
raw: true,
logging: sqlLogger(req),
include: [
  {
    attributes: ['id', 'processName', 'groupName', 'groupId', 'index', 'processNo'],
    model: B,
    required: false,
    as: 'Bname',
  },
],});
阅读 1.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题