のっぴきならねぇ事情で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