我正在对两个应该关联的表运行一个简单的查询,但我不断收到以下消息:
item_translation 与项目无关!
基本上item_translation
应该属于item
. 根据文档,我已正确完成所有操作。以下是模型:
项目翻译模型:
module.exports = function () {
return function (app) {
/** @type {Sequelize.Sequelize} */
const sequelize = app.get('sequelize')
const ItemTranslation = sequelize.define('item_translation', {
_id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
sourceId: {
type: Sequelize.STRING,
allowNull: false,
references: {
model: 'item',
key: '_id'
},
onDelete: 'cascade',
onUpdate: 'cascade'
},
text: {
type: Sequelize.STRING,
allowNull: false
}
}, {
freezeTableName: true
})
ItemTranslation.associate = function () {
ItemTranslation.belongsTo(sequelize.models.item)
}
}
}
商品型号:
module.exports = function () {
return function (app) {
/** @type {Sequelize.Sequelize} */
const sequelize = app.get('sequelize')
sequelize.define('item', {
_id: {
type: Sequelize.INTEGER,
allowNull: false,
primaryKey: true,
autoIncrement: true
},
text: {
type: Sequelize.TEXT,
allowNull: true
}
}, {
freezeTableName: true
})
}
}
我错过了什么吗?