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

293
Views
Sequelize: How to extract data with a relation hasMany | belongsTo?

Guys i want to find all budgets, from Budget, where my category (aka companies) is the value we write in the link of a website ex: /admin/budgets/:id (id in the link would be 2111, a number of a company)

How can i extract from sequelize rows, that contains only the id?

router.get("/admin/budgets/:id", adminAuth, (req,res) => {
    var id = req.params.id;
    if(isNaN(id)){
        res.redirect("/admin/budgets");
    }


    Budget.findByPk(id).then(budget => {
        if(budget != undefined){
            
            Category.findByPk(id).then(categories=> {
                res.render("admin/budgets/:id", {categories:categories, budget:budget})
            })
        }else {
            res.redirect("/admin/budgets");
        }
    }).catch(erro  => {
        res.redirect("/admin/budgets");
    })
})

Category.hasMany(Budget); // 1-p-M Budget.belongsTo(Category); //1-p-1

about 4 years ago · Santiago Gelvez
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!