
const { STRING, INTEGER } = app.Sequelize;
const model = {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
fileName: STRING(30),
fileId: {
type: INTEGER,
unique: true,
allowNull: false,
references: {
model: 'article',
key: 'id',
},
},
fileUrl: STRING,
};
const Article = app.model.define('article', model);
app.model.Article.hasOne(app.model.File, { foreignKey: 'fileId' });
return class extends Article { };
const model = {
id: { type: INTEGER, primaryKey: true, autoIncrement: true },
creator: STRING(30),
content: TEXT,
text: TEXT,
title: STRING(40),
created_at: DATE,
updated_at: DATE,
isShow: BOOLEAN,
};
const File = app.model.define('file', model);
app.model.File.belongsTo(app.model.Article, { foreignKey: 'id', targetKey: 'fileId' });
return class extends File {};
``
@atian25
定义表关系放在associate 函数里面,因为执行app.model.define时, Article还没有被绑定到app.model上面
Article.associate = function() {
app.model.Article.hasOne(app.model.File, { foreignKey: 'fileId' });
}
问题已有回答,我关掉先
定义表关系放在associate 函数里面,因为执行app.model.define时, Article还没有被绑定到app.model上面
Article.associate = function() { app.model.Article.hasOne(app.model.File, { foreignKey: 'fileId' }); }

但是会有这个报错呢
@daiyang123456 我也报这个错 解决了吗?
定义表关系放在associate 函数里面,因为执行app.model.define时, Article还没有被绑定到app.model上面
Article.associate = function() { app.model.Article.hasOne(app.model.File, { foreignKey: 'fileId' }); }
但是会有这个报错呢
我也报这个错。。请问解决了吗
@daiyang123456 我也报这个错 解决了吗?
请问您解决了吗?
@daiyang123456 我也报这个错 解决了吗?
请问您解决了吗?
Article: any = .....就可以了
Most helpful comment
但是会有这个报错呢