在 Sequelize 中对加入的 table 使用函数

Using function on joined table in Sequelize

我正在尝试 运行 TIMESTAMPDIFF() 连接 table 的列。

现在,我正在使用这个:

  Project
    .findAll({
      include: [Note, Link],
      attributes: [
        [sequelize.fn('TIMESTAMPDIFF', sequelize.literal('SECOND'), sequelize.literal('CURRENT_TIMESTAMP'), sequelize.col('notes.createdAt')), 'diff']
      ]
    })
    .then(res.send.bind(res));

但是 diff 列分组到 Projects 结果中,而不是 Projects.

中的 Notes 结果

例如,我期待这个:

[
   {id: 1, name: "Some Project", notes: [id: 33, diff: 123] },
   {id: 2, name: "Another Project", notes: [id: 34, diff: 456] }     
]

但是,我得到这个:

[
   {id: 1, name: "Some Project", diff: 123, notes: [id: 33] },
   {id: 2, name: "Another Project", diff: 456, notes: [id: 34] }    
]

是否可以在加入的 table 上使用 运行 函数?

Project
.findAll({
  include: [{
    model: Note,
    attributes: [[sequelize.fn('TIMESTAMPDIFF', sequelize.literal('SECOND'), sequelize.literal('CURRENT_TIMESTAMP'), sequelize.col('notes.createdAt')), 'diff']
  }, Link]
})