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

Commit 42ede1e9 by Sascha Depold

transaction support for belongs to getters

1 parent c480c35b
...@@ -45,8 +45,9 @@ module.exports = (function() { ...@@ -45,8 +45,9 @@ module.exports = (function() {
, primaryKey = primaryKeys.length === 1 ? primaryKeys[0] : 'id' , primaryKey = primaryKeys.length === 1 ? primaryKeys[0] : 'id'
obj[accessor] = function(params) { obj[accessor] = function(params) {
var id = this[self.identifier] var id = this[self.identifier]
, where = {} , where = {}
, options = Utils._.pick(params || {}, 'transaction')
where[primaryKey] = id where[primaryKey] = id
...@@ -60,7 +61,7 @@ module.exports = (function() { ...@@ -60,7 +61,7 @@ module.exports = (function() {
params = id params = id
} }
return self.target.find(params) return self.target.find(params, options)
} }
return this return this
......
...@@ -20,6 +20,39 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() { ...@@ -20,6 +20,39 @@ describe(Support.getTestDialectTeaser("BelongsTo"), function() {
}) })
}) })
describe('getAssociation', function() {
it('supports transactions', function(done) {
Support.prepareTransactionTest(this.sequelize, function(sequelize) {
var User = sequelize.define('User', { username: Support.Sequelize.STRING })
, Group = sequelize.define('Group', { name: Support.Sequelize.STRING })
Group.belongsTo(User)
sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Group.create({ name: 'bar' }).success(function(group) {
sequelize.transaction(function(t) {
group.setUser(user, { transaction: t }).success(function() {
Group.all().success(function(groups) {
groups[0].getUser().success(function(associatedUser) {
expect(associatedUser).to.be.null
Group.all({ transaction: t }).success(function(groups) {
groups[0].getUser({ transaction: t }).success(function(associatedUser) {
expect(associatedUser).to.be.not.null
t.rollback().success(function() { done() })
})
})
})
})
})
})
})
})
})
})
})
})
describe('setAssociation', function() { describe('setAssociation', function() {
it('supports transactions', function(done) { it('supports transactions', function(done) {
Support.prepareTransactionTest(this.sequelize, function(sequelize) { 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!