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

470
Views
How to return result from include model in same level of main model in Sequelize?

This is the code and result that I have done in my project. I would like to get the result of include model in the same result with the main model. the below code is what I have done.

Sequelize query:

 User.findAll({
        include: [{
                model: Position,
                attributes: ['POSITION_NAME'],
            }
        ]
    }).then(user => {
        res.json({
            data: user
        })
    }).catch(error => {
        console.log(error)
    })

result that I get

     [
        {
            "ID": 2,
            "NAME": "AAA",
            "LAST_NAME": "BBB",
            "Position": {
                "POSITION_NAME": "ວິຊາການສັນຍາຈ້າງ"
            }
        }
]

result that I want:

     [
        {
            
        "ID": 2,
        "NAME": "AAA",
        "LAST_NAME": "BBB",
        "POSITION_NAME": "ວິຊາການສັນຍາຈ້າງ"
        }
]
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

try like this .

User.findAll({
    attributes: ["ID", "NAME", ["Position.POSITION_NAME", "POSITION_NAME"]],
    include: [{
        model: Position,
        attributes: [],
    }
    ],
    raw:true
}).then(user => {
    res.json({
        data: user
    })
}).catch(error => {
    console.log(error)
})
over 4 years ago · Santiago Trujillo 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!