pInvent.js
module.exports = (sequelize, DataTypes) => {
const PInvent = sequelize.define('prod_invent', {
id: {primaryKey: true, type: DataTypes.INTEGER, autoIncrement: true, allowNull: false, unique: true},
sku_id: {
type: DataTypes.STRING,
allowNull: false,
unique: true
}
});
PInvent.associations = (db) => {
PInvent.belongsToMany(db.cTags, {
as: 'CTags',
through: 'c_prod',
foreignKey: 'prod_id',
otherKey: 'c_id'
});
};
return PInvent
}
pCure.js
module.exports = (sequelize, DataTypes) => {
const PCure = sequelize.define('prod_cure', {
id: {primaryKey: true, type: DataTypes.INTEGER, autoIncrement: true, allowNull: false, unique: true},
c_tag: {type: DataTypes.STRING, allowNull: false, unique: true}
});
PCure.associations = (db) => {
PCure.belongsToMany(db.pInvent, {
as: 'CProd',
through: 'c_prod',
foreignKey: 'c_id',
otherKey: 'prod_id'
});
};
return PCure
}
db.js
db.pInvent = require('../model/pInvent')(sequelize, Sequelize);
db.cTags = require('../model/pCure')(sequelize, Sequelize);
db.cTags.associations(db);
Теперь, когда я пишу код, как показано ниже:
db.cTags.findAll({
attributes: ['prod_cure.*', 'prod_invent.*', [Sequelize.fn('COUNT', Sequelize.col('prod_invent.id')), 'PostCount']],
include: [{
model: db.pInvent, as: 'CProd'
}]
}).then((data) => {
res.json({info:data})
}).catch((err) => {
res.json({errInfo:err})
})
выдает ошибку, как показано ниже:
Неизвестная таблица 'prod_invent'
Что я хочу здесь, я хотел вычислить количество вложенных объектов, ноя не в состоянии сделать.