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

Commit 12b58b68 by Sascha Depold

Merge pull request #213 from innofluence/master

Fix for issue 210
2 parents 5d053be7 14cb25aa
...@@ -15,7 +15,7 @@ module.exports = (function() { ...@@ -15,7 +15,7 @@ module.exports = (function() {
HasManySingleLinked.prototype.injectSetter = function(emitter, oldAssociations, newAssociations) { HasManySingleLinked.prototype.injectSetter = function(emitter, oldAssociations, newAssociations) {
var self = this var self = this
, options = this.options || {} , options = this.__factory.options
// clear the old associations // clear the old associations
oldAssociations.forEach(function(associatedObject) { oldAssociations.forEach(function(associatedObject) {
......
...@@ -162,6 +162,33 @@ describe('HasMany', function() { ...@@ -162,6 +162,33 @@ describe('HasMany', function() {
}) })
}) })
}) })
it("clears associations when passing null to the set-method with omitNull set to true", function(done) {
sequelize.options.omitNull = true;
var User = sequelize.define('User', { username: Sequelize.STRING })
, Task = sequelize.define('Task', { title: Sequelize.STRING })
Task.hasMany(User)
sequelize.sync({ force: true }).success(function() {
User.create({ username: 'foo' }).success(function(user) {
Task.create({ title: 'task' }).success(function(task) {
task.setUsers([ user ]).success(function() {
task.getUsers().success(function(_users) {
expect(_users.length).toEqual(1)
task.setUsers(null).success(function() {
task.getUsers().success(function(_users) {
expect(_users.length).toEqual(0)
done()
})
})
})
})
})
})
})
})
}) })
describe('(N:M)', function() { describe('(N:M)', function() {
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!