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

196
Views
Does Sequelize provide a way to conditionally select attributes?

I am trying to conditionally select specific attributes to retrieve from the included Model in a findOne() Sequelize function, based on values from the 'parent' Model.

Does anyone know if this is possible in a single query?

Here's my attempt so far -

let article = await Article.findOne({
      where: { slug, published: true },
      include: [{
        model: User,
        as: 'author',
        attributes: {
          $col: Article.usepseudonym
            ? ['pseudonym']
            : ['id', 'name', 'avatarUrl']
        }
      }]
    })

The Sequelize function is not throwing an error and is returning all of the User attributes when I only require specific fields.

about 4 years ago · Juan Pablo Isaza
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!