I would like to make a relational query with sequelize type right Join

Asked

Viewed 27 times

0

I need to perform this type of query with sequelize, for a specific data return.

"SELECT p.id, p.nome , p.numero_face, zp.zona_id from pessoa as p 
    right join zona_pessoa as zp on zp.pessoa_id = p.id where zona_id = 3";

In this example of query below I bring the data without a relation to another table "zona_pessoa", but I have tried several ways and can not handle this query.

async getPessoasSemFaces(req, res) {
    try {
      const pessoas = await Pessoa.findAll({
        where: { numero_face: { [Op.is]: null } },
        attributes: ['id', 'nome', 'numero_face'],
      });
      if (!pessoas) {
        return res.status(404).json({ error: 'Nenhuma pessoa sem face encontrada' });
      }
      return res.status(200).json(pessoas);
    } catch {
      return res.status(500).json({ error: 'Erro interno' });
    }
  }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.