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

Commit b66d9ad9 by Mick Hansen

fix(hasOne): make sure it uses the transaction for the select

1 parent a3aa0824
...@@ -67,6 +67,8 @@ module.exports = (function() { ...@@ -67,6 +67,8 @@ module.exports = (function() {
if (!Utils._.isUndefined(params)) { if (!Utils._.isUndefined(params)) {
if (!Utils._.isUndefined(params.attributes)) { if (!Utils._.isUndefined(params.attributes)) {
params = Utils._.extend({where: where}, params) params = Utils._.extend({where: where}, params)
} else if (!params.where) {
params.where = where
} }
} else { } else {
params = {where: where} params = {where: where}
...@@ -83,6 +85,7 @@ module.exports = (function() { ...@@ -83,6 +85,7 @@ module.exports = (function() {
options.transaction = params.transaction; options.transaction = params.transaction;
delete params.transaction; delete params.transaction;
} }
return self.target.find(params, options) return self.target.find(params, options)
} }
......
...@@ -29,6 +29,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -29,6 +29,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
Group.hasOne(User) Group.hasOne(User)
sequelize.sync({ force: true }).success(function() { sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(fakeUser) {
User.create({ username: 'foo' }).success(function(user) { User.create({ username: 'foo' }).success(function(user) {
Group.create({ name: 'bar' }).success(function(group) { Group.create({ name: 'bar' }).success(function(group) {
sequelize.transaction(function(t) { sequelize.transaction(function(t) {
...@@ -38,7 +39,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -38,7 +39,9 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
expect(associatedUser).to.be.null expect(associatedUser).to.be.null
Group.all({ transaction: t }).success(function(groups) { Group.all({ transaction: t }).success(function(groups) {
groups[0].getUser({ transaction: t }).success(function(associatedUser) { groups[0].getUser({ transaction: t }).success(function(associatedUser) {
expect(associatedUser).to.be.not.null expect(associatedUser).not.to.be.null
expect(associatedUser.id).to.equal(user.id)
expect(associatedUser.id).not.to.equal(fakeUser.id)
t.rollback().success(function() { done() }) t.rollback().success(function() { done() })
}) })
}) })
...@@ -51,6 +54,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() { ...@@ -51,6 +54,7 @@ describe(Support.getTestDialectTeaser("HasOne"), function() {
}) })
}) })
}) })
})
it('should be able to handle a where object that\'s a first class citizen.', function(done) { it('should be able to handle a where object that\'s a first class citizen.', function(done) {
var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING }) var User = this.sequelize.define('UserXYZ', { username: Sequelize.STRING })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!