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

Omar Martin
Omar Martin used Ask the Experts™
on
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

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
What happens if you try them individually?

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

Author

Commented:
If I try them individually, the data which which is last is returned.
Bridgemaker
Commented:
This solution seem to have done the trick....

{
    gigs:data[0],
    gigs2:data[1]  // <----- Change this key name gigs2
}

// OR

{
     gigs: [ ...data[0] , ...data[1] ] // <--- Merge result into one
}
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
Yes that will do it - I missed that - properties in a JavaScript object must be unique
Omar MartinBridgemaker

Author

Commented:
Thank you...
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial