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

134
Views
Multiple includes in one model querying

sorry about my English. I want to do multiple include associations within a findOne using sequelize. When I do separate includes everything works perfectly. I'll contrast below what works and what doesn't.

// that doesn't work
const post = await Post.findOne({
         where: { post_url: post_url },
         include: { // this include dont work
            association: 'postAuthor',
            attributes: ['name'],
         },
         include: {
            association: 'comments',
            attributes: ['comment'],
            include: {
               association: 'commentAuthor',
               attributes: ['name']
            }
         }
      });

But if I make each sentence separate it works

// this work
     include: {
            association: 'postAuthor',
            attributes: ['name'],
         },

Again sorry for the English.

In short, I need to make both includes work at the same time. The include inside the include works perfectly (commentAuthor In comments).

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

      where: { post_url: post_url },
         include: [
            { association: 'postAuthor', attributes: ['name'] },
            {
               association: 'comments', attributes: ['comment'],
               include: [{
                  association: 'commentAuthor',
                  attributes: ['name']
               }]
            }
         ]
      });
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!