buscar dados de chave estrangeira em sequelizar
Generic :
TableB.belongsTo(models.TableA, { foreignKey: 'someID', targetKey: 'notTableAID' } );
TableA.hasOne(TableB, {
sourceKey: 'someNonPrimaryKeyColumnOnTheSOurceModel',
foreignKey: 'matchingColumnOnTheTargetModel'
});
Example :
// associations
assetAuditSubmissionsModel.hasOne(assetInfoModel, {
foreignKey: "assetSerialNumber",
sourceKey: "assetSerialNumber",
});
assetInfoModel.belongsTo(assetAuditSubmissionsModel, {
foreignKey: "assetSerialNumber",
targetKey: "assetSerialNumber",
});
Tanishq Vyas