How to make condition in two different tables with sequelize?

Asked

Viewed 498 times

1

How can I make this select in sequelize?

  select 
        prestadores.status, 
        financeiros.status as prestador_status from prestadores  
  left join financeiros on prestadores.financeiro_id = financeiros.financeiro_id
  where (financeiros.status = 'ok' and prestadores.status <> 'BLOQ_ADMIN' ) or 
  prestadores.status = 'LIB_ADMIN'
  var prestadores = await Prestador.findAll({
    include: [{
      model: Financeiro,
      as: 'financeiro',
      required: false,
    }],

    where: {

    }
  });

1 answer

0

I ended up using the "literal" sequel.

  var prestadores = await Prestador.findAll({
    include: [{
      model: Financeiro,
      as: 'financeiro',
      required: false,
    }],

    where: literal("`Prestador`.`status` = 'LIB_ADMIN' OR `financeiro`.`status` = 'ok'"),
  });

Browser other questions tagged

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