title: Q.all and an array of promises don't seem to be working
body: <p>I'm trying to use Q to do some work. I loop through and call a function which saves data to the database and returns a promise. Once those are done I need to do something else, but the Q.all finishes, although I can see each resolve being called. I've going nuts, any ideas?</p>
  
  <p>The setup:</p>
  
  <pre><code>// save the divisions and then do the division checks
  // data.divisions is an array of objects
  var promises = [];
  data.divisions.forEach(function(dd){
      var d = new grpl.division.Division(dd),
          p = d.save();
      promises.push(p);
  });
  
  Q.all(promises)
  .then(function(){
      // do some other stuff here
      // this never actually gets called
  
  }).fail(function(err){
      cb(err);
  }).done();
  </code></pre>
  
  <p>And here's <code>d.save()</code></p>
  
  <pre><code>Division.prototype.save = function(){
      var self = this
          d = Q.defer();
  
      getPool().getConnection(function(err, db){
          if(err){ d.reject(err); return false; }
  
          var fields = {
              division_id: self.division_id,
              season_id: self.season_id,
              title: self.title,
              cap: self.cap,
              display_order: self.display_order
          };
  
          db.query("INSERT INTO division SET ? ON DUPLICATE KEY UPDATE ?", [fields, fields], function(err, result) {
              if(err){ d.reject(err); return false; }
              d.resolve(true);// this does get resolved for each division
          });
      });
  
      return d.promise;
  }
  </code></pre>
  
  <p>I have no clue what's wrong, but it just stops and doesnt appear to ever resolved my Q.all call.</p>
  
  <p><strong>UPDATE</strong>
  It appears that the initial call to save will function properly, but subsequent save calls appear to be resolving the same promise as the first call. I wrapped the body of the save code into a variable function which I called from save and its working but I'm not 100% sure why (prototypical inheritance is my fallback whenever JS really confuses me). Any explanations or better ways to do it?</p>
  
  <pre><code>Division.prototype.save = function(){
      var func = function(self){
          var d = Q.defer();
  
          d.promise.division_id = self.division_id;
  
          getPool().getConnection(function(err, db){
              if(err){ d.reject(err); return false; }
  
              var fields = {
                  division_id: self.division_id,
                  season_id: self.season_id,
                  title: self.title,
                  cap: self.cap,
                  display_order: self.display_order
              };
  
              db.query("INSERT INTO division SET ? ON DUPLICATE KEY UPDATE ?", [fields, fields], function(err, result) {
                  if(err){ d.reject(err); return false; }
                  d.resolve(result);
              });
          });
  
          return d.promise;
      }
  
      return func(this);
  }
  </code></pre>