这里我创建了两张表,一张是文章表,一张是文章类型表
文章表model
// app/model/Article.ts
import { Application } from 'egg';
export default function(app: Application) {
const { INTEGER, STRING } = app.Sequelize;
const Article = app.model.define('article', {
id: {
type: INTEGER,
primaryKey: true,
autoIncrement: true,
},
title: STRING(255),
case_id: INTEGER,
}, {
timestamps: false, // 去除createAt updateAt
freezeTableName: true, // 使用自定义表名
});
return class extends Article {
static associate() {
app.model.Article.belongsTo(app.model.Case, { foreignKey: 'case_id', targetKey: 'id' });
}
};
}
文章类型表model
import { Application } from 'egg';
export default