Skip to content

Instantly share code, notes, and snippets.

@mickhansen
Created December 30, 2013 20:31
Show Gist options
  • Save mickhansen/8187691 to your computer and use it in GitHub Desktop.
Save mickhansen/8187691 to your computer and use it in GitHub Desktop.
Transactings.findAll({
where: {
status: 'PENDING'
},
include: [Account]
}).done(function (err, transactings) {
async.forEach(transactings, function (transacting, callback) {
sequelize.transaction(function(t) {
var chainer = new Sequelize.QueryChainer()
chainer.add(transacting.account.increment('balanace', transacting.amount))
chainer.add(Transaction.create({amount: transacting.amount}))
chainer.error(t.rollback)
chainer.success(t.commit)
t.done(callback)
})
}, function () {
// Were done
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment