【发布时间】:2018-05-17 14:35:13
【问题描述】:
我有一个exports file,其中包含所有的续集模型,然后定义模型之间的关系。它看起来像:
// Snippet from the global init file
for (let modelFile of modelFileList) {
// ... Some code ...
// Require the file
appliedModels[modelName] = require(`../${MODEL_DIR}/${modelFile}`).call(null, _mysql);
}
//Define the relationship between the sql models
_defineRelationship(appliedModels);
function _defineRelationship(models) {
models._planAllocationModel.belongsTo(models._subscriptionModel, {
foreignKey: 'subscription_id',
targetKey: 'subscription_id'
});
}
但是当我尝试包含以下模型时:
_subscriptionModel.findAll({
where: {
start_date: {
_lte: today // Get all subscriptions where start_date <= today
}
},
limit,
include: [
{
model: _planAllocationModel
}
]
});
sequelize 抛出错误:SequelizeEagerLoadingError: tbl_plan_allocation is not associated to tbl_subscription_info! 这可能是什么原因?我已经初始化了两个模型之间的关系。
【问题讨论】:
标签: node.js orm sequelize.js