So basically I am having trouble making an asynchrounous call with express, node, and knex. The overall flow of this code snippet is grabbing data from one of my tables, the data in this table references another table, so I am using the modId to pull data from my second table, I am getting the modId from each index and then using each one to pull the correlating mod from the other table, but it breaks at the for loop and the array is empty if I call on it anywhere outside of the for loop because it's running the return before the for loop. I have tried this many many ways and can't find a good solution. Here's the code:vehicleKnownVehicleIdByUrl(vehicleUrl).then(function(vehicleId) { console.log(vehicleId); knex.select().from('vehicle_mods').where('vehicleId', vehicleId).then(function(rows) { if (!rows.length) { return res.status(200).json({ message:'No mods found' }); } let mods = [] for( var i = 0; i < rows.length; i++){ knex.select().from('mods').where({id : rows[i].modId}).then(function(rows) { mods.push(rows); }) return rows } console.log(mods); return res.json(mods) ......Any help would be greatly appreciated!
Submitted October 03, 2017 at 01:36AM by trapfozz
No comments:
Post a Comment