のっぴきならねぇ事情でassociationナシでincludeしたいとき
こんなふうに解消した
await model.findAll({
include: [
"table1",
{
model: "table2",
required: true,
// association objectは好きなやつで
association: new HasOne(
model,
"table2",
{
as: "table2",
foreignKey: "piyo_id",
sourceKey: "piyo_id",
}
),
},
],
});
参考
https://stackoverflow.com/questions/47215961/sequelize-js-join-tables-without-associations
![]() |
![](https://www17.a8.net/0.gif?a8mat=1U5RVD+8J7VVE+249K+BWGDT)