我在续集方面有一些问题。 我的表信用用credit_types进行引用。 credit_types 1:N学分
这说明出现了以下问题:credit_types与信用无关!
// Models / creditTypes.js
const CreditsTypes = sequelize.define(
"credit_types",
{
credit_t_id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
description: {
type: Sequelize.STRING,
},
},
{
timestamps: false,
freezeTableName: true,
}
);
module.exports = CreditsTypes;
// Models / credits.js
const Credits = sequelize.define(
"credits",
{
credit_id: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true,
},
debtor_name: {
type: Sequelize.STRING,
},
total_value: {
type: Sequelize.NUMBER,
},
due_date: {
type: Sequelize.STRING,
},
credit_description: {
type: Sequelize.STRING,
},
credit_t_id: {
type: Sequelize.INTEGER,
references: {
model: "credit_types",
key: "credit_t_id",
},
},
client_id: {
type: Sequelize.INTEGER,
},
},
{
timestamps: false,
freezeTableName: true,
}
);
Credits.associate = model => {
Credits.hasMany(CreditsTypes, { foreignKey: "credit_t_id" });
};
module.exports = Credits;
// controller / client.js
const credit = await Credits.findAll({
include: [
{
model: CreditsTypes,
},
],
});
我尝试了几件事,但是没有用。