Is there a way to join tables that don't have associations defined using include
in sequelize? This is not a duplicate of this. I am talking about tables that are not associated at all but having columns that I want to join on.
Example:
select * from bank
left outer join account
on account.bank_name = bank.name
The above query will return all records in table bank
regardless of the existence of an account
record where the specified constraints apply.
In sequelize this would look something like the following, if models bank
and account
were associated on account.bank_name = bank.name
:
bank.findAll({
include: [{
model: account,
required: false,
}]
})
However, what if the models are not associated? Is there a way to write my own custom on
section or equivalent:
bank.findAll({
include: [{
model: account,
required: false,
on: {
bank_name: Sequelize.col('bank.name')
}
}]
})
I vaguely remember reading something about this but I cannot seem to find that doc anywhere now. If you can point to the correct section in the docs it would be greatly appreciated.