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

Commit 3b2c0ee0 by Mick Hansen

Merge pull request #1217 from saschagehlich/bugfix/find-transaction-option

Bugfix: Make sure DAO#find takes `transaction` option in first parameter
2 parents 4eda9cb6 b859ca44
......@@ -58,7 +58,6 @@ module.exports = (function() {
obj[this.accessors.get] = function(params) {
var id = this[self.identifier]
, where = {}
, options = Utils._.pick(params || {}, 'transaction')
where[primaryKey] = id
......@@ -72,7 +71,7 @@ module.exports = (function() {
params = id
}
return self.target.find(params, options)
return self.target.find(params)
}
return this
......
......@@ -536,7 +536,7 @@ module.exports = (function() {
plain: true,
type: 'SELECT',
hasJoin: hasJoin
}, queryOptions))
}, queryOptions, { transaction: (options || {}).transaction }))
}
DAOFactory.prototype.aggregate = function(field, aggregateFunction, options) {
......
......@@ -236,7 +236,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
paranoid: true,
underscored: true
})
UserTable.sync({force: true}).success(function() {
UserTable.create({aNumber: 30}).success(function(user) {
UserTable.count().success(function(c) {
......@@ -466,6 +466,25 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
describe('find', function() {
it('supports the transaction option in the first parameter', function(done) {
Support.prepareTransactionTest(this.sequelize, function(sequelize) {
var User = sequelize.define('User', { username: Sequelize.STRING, foo: Sequelize.STRING })
User.sync({ force: true }).success(function() {
sequelize.transaction(function(t) {
User.create({ username: 'foo' }, { transaction: t }).success(function() {
User.find({ where: { username: 'foo' }, transaction: t }).success(function(user) {
expect(user).to.not.be.null
t.rollback().success(function() { done() })
})
})
})
})
})
})
})
describe('findOrInitialize', function() {
it('supports transactions', function(done) {
Support.prepareTransactionTest(this.sequelize, function(sequelize) {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!