Using loops and promises in transactions in Sequelize
<p>I am currently building a Nodejs, Express, Sequelize (w. PostgreSQL) app, and have run into a few problems with using promises together with transactions and loops.</p>

<p>I am trying to figure out how to use a for loops in a transaction. I am trying to loop through a list of members and create a new user in the database for each of them. </p>

<p>I know the following code is wrong but it shows what I am trying to do.</p>

<p>Can anyone point me in the right direction?</p>

<pre><code>        var members = req.body.members;
        models.sequelize.transaction(function (t) {
            for (var i = 0; i &lt; members.length; i++) {
                return models.User.create({'firstname':members[i], 'email':members[i], 'pending':true}, {transaction: t}).then(function(user) {
                    return user.addInvitations([group], {transaction: t}).then(function(){}).catch(function(err){return next(err);});
                })
            };
        }).then(function (result) {
            console.log("YAY");
        }).catch(function (err) {
            console.log("NO!!!");
            return next(err);
        });
</code></pre>