不要怂,就是干,撸起袖子干!

Commit e2efb566 by Sascha Depold

transaction support for updateAttributes

1 parent b80aa206
......@@ -278,9 +278,14 @@ module.exports = (function() {
return validator.hookValidate()
}
DAO.prototype.updateAttributes = function(updates, fields) {
DAO.prototype.updateAttributes = function(updates, fieldsOrOptions) {
if (fieldsOrOptions instanceof Array) {
fieldsOrOptions = { fields: fieldsOrOptions }
}
this.setAttributes(updates)
return this.save(fields)
return this.save(fieldsOrOptions)
}
DAO.prototype.setAttributes = function(updates) {
......
......@@ -482,7 +482,7 @@ module.exports = (function() {
return new Utils.CustomEventEmitter(function(emitter) {
var chainer = new Utils.QueryChainer()
chainer.add(self, 'queryAndEmit', [[sql, dao], 'delete'])
chainer.add(self, 'queryAndEmit', [[sql, dao, options], 'delete'])
chainer.runSerially()
.success(function(results){
......
......@@ -1314,6 +1314,28 @@ describe(Support.getTestDialectTeaser("DAO"), function () {
})
describe('updateAttributes', function() {
it('supports transactions', function(done) {
Support.prepareTransactionTest(dialect, this.sequelize, function(sequelize) {
var User = sequelize.define('User', { username: Support.Sequelize.STRING })
User.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
sequelize.transaction(function(t) {
user.updateAttributes({ username: 'bar' }, { transaction: t }).success(function() {
User.all().success(function(users1) {
User.all({ transaction: t }).success(function(users2) {
expect(users1[0].username).to.equal('foo')
expect(users2[0].username).to.equal('bar')
t.rollback().success(function(){ done() })
})
})
})
})
})
})
})
})
it("updates attributes in the database", function(done) {
this.User.create({ username: 'user' }).success(function(user) {
expect(user.username).to.equal('user')
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!