Reputation: 424
Hi got a question of sequelize js and transactions. So what i am trying to do is nest inserts and commit on success, rollback otherwise here is a snippet which isn't working for me for some reason or another.
sequelize()
.transaction(function(t){
myModel
.create({
name: 'shawn;
}, {transaction: t})
.success(function(newModel) {
myModel
.create({
name: 'shawn;
}, {transaction: t})
.success(function(newModel) { t.commit()})
.error(function(err) {t.rollback()})
}
.error(function(err) {t.rollback()});
});
Don't mind any syntax error the logic which i am looking to debug. The problem occurs when i replace the commit statement on success with a rollback i dont get the 2 inserts rows rolled back?
Regards Shawn
Upvotes: 2
Views: 2950
Reputation: 4843
debug this, if error exist, you see message in console and rollback is run, else ...
sequelize()
.transaction(function(t){
myModel.create({name: 'shawn'}).success(function(newModel) {
console.log('success1')
myModel.create({name: 'shawn'})
.success(function(newModel){
console.log('success2');
t.commit();
})
.error(function(err){
console.log('error2')
t.rollback();
});
}).error(function(err) {
console.log('error1')
t.rollback()
});
});
Upvotes: 1