Answer the question
In order to leave comments, you need to log in
Sequelize PG query not working?
Hello, tell me why the request in Sequelize does not work, there is such an error in the response
SequelizeDatabaseError: missing FROM-clause entry for table "accounts"
'SELECT "proxy".*, "proxyAccounts"."id" AS "proxyAccounts.id" FROM (SELECT "proxy"."id", count("accounts"."id") AS "likecount" FROM "proxies" AS "proxy" LIMIT 1) AS "proxy" LEFT OUTER JOIN "accounts" AS "proxyAccounts" ON "proxy"."id" = "proxyAccounts"."id_proxy";'
const accounts = sequelize.define('accounts', {
id_proxy: {
type: Sequelize.INTEGER,
allowNull: true,
foreignKey: true
}
})
const proxy = sequelize.define('proxy', {
take_at: {
type: Sequelize.DATE,
}
})
proxy.hasMany(accounts, { foreignKey: 'id_proxy', as: 'proxyAccounts' })
accounts.belongsTo(proxy, { foreignKey: 'id_proxy', as: 'proxyAccounts' })
models.proxy.findOne({
attributes: ['id',
[sequelize.fn('count', sequelize.col('accounts.id')), 'countConnect']
],
where: {
countConnect: {
[Op.lte]: 10
}
},
include: [{
attributes: ['id'],
model: models.accounts,
as: 'proxyAccounts'
}]
}).then(data => {
console.log(data.dataValues)
}).catch(error => {
console.error(error)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question