A
A
Alex102142021-07-29 10:50:07
Node.js
Alex10214, 2021-07-29 10:50:07

How to implement left join in Sequelize?

Hello I am new to node.js and sequelize. I have a query like this:

SELECT statistics_description.title, accounts_statistics.value  
FROM accounts_statistics LEFT JOIN statistics_description 
ON accounts_statistics.name = statistics_description.name

Help implement the LEFT JOIN method with sequelize. If possible, at least with a brief explanation. Thank you very much.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
Yuriy Vorobyov, 2021-07-29
@Alex10214

Use required: falsefor left join

AccountsStatisticsModel.findAll({
  where: { name: '$StatisticsDescriptionModel.name$' }, 
  include:[
    { 
      model: StatisticsDescriptionModel,
      attributes: ['title', 'name'],
      required: false,
    }
  ],
  attributes: ['value', 'name'],
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question