Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

where condition in literal #1470

Closed
naveenunic opened this issue Feb 20, 2024 · 1 comment
Closed

where condition in literal #1470

naveenunic opened this issue Feb 20, 2024 · 1 comment

Comments

@naveenunic
Copy link

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

@WikiRik
Copy link
Member

WikiRik commented Feb 21, 2024

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

@WikiRik WikiRik closed this as not planned Won't fix, can't repro, duplicate, stale Feb 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants