Node.js &引用&书信电报;模型>;“未定义”;创建Sequelize模型关联时
我正在尝试一些应该很简单的东西,但是没有互联网的搜索帮助我解决这个具体问题 使用Sequelize,我对两个简单的数据库表进行了建模,作为工作中的概念证明。以下是Node.js &引用&书信电报;模型>;“未定义”;创建Sequelize模型关联时,node.js,express,sequelize.js,Node.js,Express,Sequelize.js,我正在尝试一些应该很简单的东西,但是没有互联网的搜索帮助我解决这个具体问题 使用Sequelize,我对两个简单的数据库表进行了建模,作为工作中的概念证明。以下是Person和NaturalPerson模型: import { NaturalPerson } from './natural_person'; import Connection from './database/database.conn'; import { Model, DataTypes } from "sequelize"
Person
和NaturalPerson
模型:
import { NaturalPerson } from './natural_person';
import Connection from './database/database.conn';
import { Model, DataTypes } from "sequelize";
export class Person extends Model {
static isNaturalPerson(id) {
return Person.findOne({
include: [{
model: NaturalPerson,
required: true
}],
where: { id: id }
});
}
}
Person.init({
'id': {
type: DataTypes.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
'creation_date': {
type: DataTypes.DATEONLY,
allowNull: false
}
}, {
sequelize: Connection,
timestamps: false,
freezeTableName: true,
tableName: 'person',
modelName: 'Person'
});
Person.hasOne(NaturalPerson, { foreignKey: 'person_id' });
export default Person;
出于某种未知的原因,如果我注释掉行NaturalPerson.belongsTo(Person,{foreignKey:'Person_id',targetKey:'id')代码>一切都很好,但取消注释会返回我
ReferenceError: Person is not defined
at Object.<anonymous> (<source code path>\natural_person.js:45:31)
ReferenceError:未定义人员
反对。(\natural_person.js:45:31)
我不知道可能是什么问题。尽管我知道它是一个简单的未定义对象,但如果导入是正确的,我无法理解为什么它是未定义的。任何想法都将受到欢迎=(我实际上认为这可能是一个循环引用问题,但由于我严格按照Sequelize文档描述的用例制作了这个示例,我仍然被卡住了……我有同样的问题,你能解决吗?我也有这个问题,有人找到解决方案了吗?
ReferenceError: Person is not defined
at Object.<anonymous> (<source code path>\natural_person.js:45:31)