Link to home
Start Free TrialLog in
Avatar of Omar Martin
Omar MartinFlag for United States of America

asked on

Receiving data from two (2) tables at the same time

I am trying to send the results for two(2) tables using sequelize, however only the results on either one table is printed. I would like both tables to print using promises. Here is the route code:

router.get("/alldataa", (req, res) => 

Promise.all([boilerHouse.findAll(), compressorHouse.findAll()])
.then((data) => {
  res.render('gigs', {
    gigs:data[0],
    gigs:data[1],
   
   //data[0] is response from tableA find
   // data[1] is from tableB
})   
  })
  .catch(err => console.log(err)));

Open in new window

Avatar of Julian Hansen
Julian Hansen
Flag of South Africa image

What happens if you try them individually?

What do you get if you do a console.log(data) on line 5
Avatar of Omar Martin

ASKER

If I try them individually, the data which which is last is returned.
ASKER CERTIFIED SOLUTION
Avatar of Omar Martin
Omar Martin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you...
You are welcome.