I have an instance where I am trying to query two separate tables within the same GET request and then return the results to objects that can be accessed by my rendered view for use. In my current setup, the SQL queries are returning the correct commands and the first query has the results (status
) correctly returned and are accessible within my view, but I'm unable to return the second set of results (discoverySource returns undefined in my console log
), which is likely due to the fact that javascript promises can only return a single value. Is there a better way to query or return both objects?
appRoutes.route('/')
.get(function(req, res){
models.Status.findAll({
where: {
userId: req.user.user_id
},
attributes: ['statusId', 'statusDate', 'dataDateStart', 'dataDateEnd', 'title'],
order: 'statusDate DESC',
}).then(function(status,discoverySource){
models.DiscoverySource.findAll({
where: {
organizationId: req.user.organizationId
},
attributes: ['discoverySource']
})
return status;
}).then(function(status, discoverySource){
console.log(discoverySource);
res.render('pages/app/high-level-activity-feed.hbs',{
status: status,
discoverySource: discoverySource,
user: req.user
});
})
})