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

162
Views
How to make sql sequelize query with nested relations where clause

Im currently working on a budget tracking web app that has the corresponding database setup

enter image description here

So basically i have multiple transactions reladed to a single account, as well as multiple accounts related to a single user

i want to come up with a sequelize query that allows me to view every transaction done by any account corresponding to a single user

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

0

Assuming that you have associations look like this:

// these definitions are simplified for demonstration purposes
User.hasMany(Account);
Account.hasMany(Transaction);
Account.belongsTo(User);
Transaction.belongsTo(Account);

We can get all user's transactions like this:

const transactions = await Transaction.findAll({
  include: [{
    model: Account,
    required: true,
    include: [{
     model: User,
     required: true,
     where: {
       id: userId // here is the condition on a certain user id
     }
    }]
  }]
})
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!