Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

126
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!