Bluebird Promise.map is not working
<p>I am trying to build associations between a question and answers. And I am using to use Bluebird's API <code>.map</code> to make sure a redirect only happens after all the <code>question.addAnswers(answer)</code> promises are done. Therefore, in my terminal, I should see something like this:</p>

<pre><code>done adding a answer to the question
done adding a answer to the question
finished
</code></pre>

<p>However, what I see is:</p>

<pre><code>finished
done adding a answer to the question
done adding a answer to the question
</code></pre>

<p>Therefore, I assume the <code>Promise.map</code> is not working at all. Did I miss something? How can I make it work?</p>

<p>Here is my code:</p>

<pre><code>router.post('/create', function(req, res) {
  models.Question.create({
    content: req.body.question
  })
  .then(function(question) {
    if (!question) {
      res.render('questions/new', {
          error: "Question \"#{req.body.question}\" fails to be created"
        });
    } else {
      // Update the new question to each user
      models.User.findAll()
      .then(function(users) {
        users.forEach(function(user) {
          user.addQuestion(question)
        });
      });
      Promise.map(req.body.answers, function(answer){
        return createAndAddToQuestion(question, answer, res)
      })
      .then(function(){
        console.log('finished')
        res.redirect("/questions/success/?question_id=" + question.id);
      });
    };
  })
})

var createAndAddToQuestion = function(question, answer, res) {
  models.Answer.create({
    content: answer
  })
  .then(function(ans) {
    if (ans) {
      var promise = question.addAnswer(ans)
      promise.then(function(){
        console.log("done adding a answer to the question")
      });
      return question.addAnswer(ans);
    } else {
      res.render('questions/new', {
        error: "Answer \"#{answer}\" fails to be created"
      });
    };
  });
}
</code></pre>

<p><em>UPDATE</em>
I just update the <code>createAndAddToQuestion</code>, so it will return a promise instead. Outcome stays the same. <code>Promise.map</code> is not working.</p>

<pre><code>var createAndAddToQuestion = function(question, answer, res) {
  models.Answer.create({
    content: answer
  })
  .then(function(ans) {
    if (ans) {
      return question.addAnswer(ans).then(function() {
        console.log('done')
      })
    } else {
      res.render('questions/new', {
        error: "Answer \"#{answer}\" fails to be created"
      });
    };
  });
}
</code></pre>