我有兩個關聯的模型-> 訂單屬于階段,我想在選擇具有所選階段.projectId 的訂單時使用 where 子句。
models.Order.findAll( {
attributes:[
'id',
'product_id',
'phase_id',
[models.Order.sequelize.fn('sum', models.Order.sequelize.col('invoiced')), 'invoiced_quantity'],
],
include: [{model:models.Phase, as:'phase', required: true}],
where:{'$phase.projectId$': chosenProject.id},
group:[
'product_id'
],
raw: true
})
但它會在 'where 子句' 中創建一個錯誤 Unknown column 'phase.projectId'
是否可以對包含的模型使用 where 子句?
uj5u.com熱心網友回復:
您可以在 include 中使用 where 子句。
models.Order.findAll( {
attributes:[
'id',
'product_id',
'phase_id',
[models.Order.sequelize.fn('sum', models.Order.sequelize.col('invoiced')), 'invoiced_quantity'],
],
include: [{model:models.Phase, as:'phase', where: {id: chosenProject.id}],
group:[
'product_id'
],
raw: true
})
和 where 子句包括 make inner join (w/o required: trueoption)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/416561.html
標籤:
