title: Do something async with underscore map
body: <pre><code>function addSomething(data) {
      var defer = q.defer();
      data = _.map(data, function(item) {
              item['something'] = callSomethingAsync();
              return item;
      });
      return defer.promise;
  }
  </code></pre>
  
  <p>How can I handle this problem. The only way I found is using Async.js.
  But maybe there is a better way using $q?</p>
  
  <p>EDIT:</p>
  
  <pre><code>function getScopes(item) {
      var defer = q.defer();
      var query = "SELECT somevalue FROM Something WHERE ID = '" + item.id + "'";
      mysql.query(query, function(err, data) {
          if (err) {
              defer.reject(err);
          } else {
              item[newkey] = data
              defer.resolve(item);
          }
      });
      defer.resolve(data)
      return defer.promise;
  }
  
  //add necessary scopes to the audit
  function addScopes(data) {
      var promises = _.map(data, function(item) {
          return getScopes(item);
      });
      return Promise.all(promises);
  }
  </code></pre>
  
  <p>How I can prevent using defer in the getScopes function?</p>
  
  <p>Edit 2:</p>
  
  <pre><code>var query = "SELECT * FROM tiscope";
  Q.nfcall(mysql.query, query).then(function(data) {
          console.log(data);
  });
  </code></pre>
  
  <p>there is nothing returned.</p>
  
  <p>Here is how I use mysql:</p>
  
  <pre><code>var sql = require('mysql');
  
  var connection = sql.createConnection({
      host     : 'xxx',
      user     : 'xxx',
      password : 'xxx',
      database : 'xxx'
  });
  
  connection.connect(function(err) {
      if (err) {
          console.error('error connecting: ' + err.stack);
      } else {
          console.log('mysql connection established');
      }
  });
  
  module.exports = connection;
  </code></pre>
  
  <p>Maybe there is the mistake.</p>