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

Commit 2977be0b by Jan Aagaard Meier

Merge pull request #658 from mweibel/fix-belongs-to-where-params

Fix belongsTo where params
2 parents 3e6c5757 67b0c6c6
......@@ -42,8 +42,10 @@ module.exports = (function() {
var id = this[self.identifier]
if (!Utils._.isUndefined(params)) {
if (!Utils._.isUndefined(params.attributes)) {
params = Utils._.extend({where: {id:id}}, params)
if (!Utils._.isUndefined(params.where)) {
params.where = Utils._.extend({id:id}, params.where)
} else {
params.where = {id: id}
}
} else {
params = id
......
......@@ -8,7 +8,10 @@ describe('BelongsTo', function() {
, Task = null
var setup = function() {
User = sequelize.define('User', { username: Sequelize.STRING })
User = sequelize.define('User', { username: Sequelize.STRING, enabled: {
type: Sequelize.BOOLEAN,
defaultValue: true
}})
Task = sequelize.define('Task', { title: Sequelize.STRING })
}
......@@ -88,6 +91,29 @@ describe('BelongsTo', function() {
})
})
it('extends the id where param with the supplied where params', function() {
Task.belongsTo(User, {as: 'User'})
Helpers.async(function(done) {
User.sync({force: true}).success(function() {
Task.sync({force: true}).success(done)
})
})
Helpers.async(function(done) {
User.create({username: 'asd', enabled: false}).success(function(u) {
Task.create({title: 'a task'}).success(function(t) {
t.setUser(u).success(function() {
t.getUser({where: {enabled: true}}).success(function(user) {
expect(user).toEqual(null)
done()
})
})
})
})
})
})
it("handles self associations", function() {
Helpers.async(function(done) {
var Person = sequelize.define('Person', { name: Sequelize.STRING })
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!