sequelize / cli

The Sequelize CLI

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

where condition in literal

naveenunic opened this issue · comments

trying to use model1 attribute Id in where condition of literal

model1.findAll({
include: [{ model: model2, as: 'model2' }],
attributes: {
include: ['*', [literal(( SELECT COUNT(*) FROM table3 T3 JOIN table2 T2 ON T3.T2Id = T2.Id JOIN table1 T1 ON T3.T1Id = T1.Id WHERE T2.Type = model2.Type AND T3.T2Id = model1.Id )),
'Alloted']]
},
})

What do you expect to happen?

where condition should take input from model1 Id

What is actually happening?

model1.Id unknown column
Output, either JSON or SQL
Unhandled rejection SequelizeDatabaseError: Unknown column 'model1.Id' in 'where clause'
Dialect: mysql
Database version: workbench 8.0
Sequelize CLI version: ^7.0.0-alpha.2
Sequelize version: ^7.0.0-alpha.2

Unfortunately with this information we are too limited to respond. Please open a discussion at https://github.com/sequelize/sequelize with some additional information about your project and maybe somebody can help you out