Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
how to Sequelize "where" accessing table and column

I am attempting to port an application that had used sequelize 3.30.4 and I'm updating to 6.13, I'm assuming some things have changed because I can't use string literals in a where clause, or so the debugger tells me.

That said, I've done some googling and have found some basic examples that make sense sure but I'm not entirely sure how to convert this string to a format acceptable for findAndCountAll to be happy.

I've attempted something like this, thinking it might at least point me in the right direction however it does not.


  let attributes = ['id', 'name', 'locationId'];
  let where = undefined;
  let order = [['name', 'ASC']];

    where = {
      classroom: {
        locationId: request.query.locationId
      }
    }

this is the line that did at one time work but no longer works.

where = `"classroom"."locationId" = ${request.query.locationId}`;
  const classrooms = await model.classroom.findAndCountAll(_.assign({},
    requestHelper.computePaginationObject(request.query.limit, request.query.page), {
    attributes,
    where: where ? [where] : undefined,
    order
  }));

how would I go about porting this into the proper format?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try something like this:

let where = {}
if (<some condition>) {
  where = {
    locationId: request.query.locationId
  }
}
const classrooms = await model.classroom.findAndCountAll(_.assign({},
    requestHelper.computePaginationObject(request.query.limit, request.query.page), {
    attributes,
    where: where,
    order
  }));
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can also try that even if the first comment of ANATOLY works wonders :

const where = <some condition> ? {locationId: request.query.locationId} :{};

const classrooms = await model.classroom.findAndCountAll(_.assign({},
        requestHelper.computePaginationObject(request.query.limit, request.query.page), {
        attributes,
        where,
        order
      }));
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda