how to add a subquery to the results of a query with axis

You dont acutally have to build a promise. You can simply send your results when they are available within your second query callback:

(err, results) => {
  if (err) {
    return res.send(err);
  } else {
    let result = results[0];
    result.relationships = [];
    connection.query(
      `SELECT
        objects.*
      FROM objects
      WHERE relationship = ${result.id}`,
      (err, rel_results) => {
        if (err) {
          return res.send(err);
        } else {
          rel_results.forEach((el) => {
            result.relationships.push(el);
          });
          // This log looks fine. result.relationhips is an array of objects.
          console.log(result);

          res.json(result);
        }
      }
    );
  }

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top