续集属于并包含
我很难在查询中使用BelongsTo关系。
这是关系:
models.Area.hasMany(models.Airport); models.Airport.belongsTo(models.Area, {foreignKey: 'areaId', as: 'area'});
现在我尝试运行一个查询:
models.Airport .findAll( { where: { active: 1 }, include: { model: models.Area } })
我得到一个错误:
Error: area is not associated to airport!
我究竟做错了什么?
我想到了。 我不能说我完全理解这个问题,但是在这里。
在创build关系时,我使用“区域”。
结果是,我需要添加为:“区域”的包括声明:
models.Airport .findAll( { where: { active: 1 }, include: { model: models.Area, as: 'area' } })
一旦匹配,事情就会好转。