Здравствуйте, подскажите, почему не работает запрос в Sequelize, в ответе вот такая ошибка
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)
})
Через PgAdmin смотрел названия таблиц, и они вот такие accounts, proxies.
Подскажите, как составить такой запрос?