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

Commit ac23e551 by Sascha Gehlich

Merge branch 'master' into feature/create-relation-objects

2 parents 73d07be6 3b2c0ee0
Showing with 113 additions and 2 deletions
......@@ -1191,17 +1191,27 @@ module.exports = (function() {
options.where = options.where || {}
var deletedAtCol = Utils._.underscoredIf(this.options.deletedAt, this.options.underscored)
, quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(deletedAtCol)
// Don't overwrite our explicit deletedAt search value if we provide one
if (!!options.where[deletedAtCol]) {
return options
}
if(this.tableName) {
quoteIdentifiedDeletedAtCol = this.QueryInterface.quoteIdentifier(this.tableName) + '.' + quoteIdentifiedDeletedAtCol
}
if (typeof options.where === "string") {
options.where += ' AND ' + this.QueryInterface.quoteIdentifier(deletedAtCol) + ' IS NULL '
options.where += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
}
else if (Array.isArray(options.where)) {
options.where[0] += ' AND ' + this.QueryInterface.quoteIdentifier(deletedAtCol) + ' IS NULL '
// Don't overwrite our explicit deletedAt search value if we provide one
if(options.where[0].indexOf(deletedAtCol) !== -1) {
return options
}
options.where[0] += ' AND ' + quoteIdentifiedDeletedAtCol + ' IS NULL '
} else {
options.where[deletedAtCol] = null
}
......
......@@ -1679,4 +1679,105 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})
describe('paranoid is true and where is an array', function() {
beforeEach(function(done) {
this.User = this.sequelize.define('User', {username: DataTypes.STRING }, { paranoid: true })
this.Project = this.sequelize.define('Project', { title: DataTypes.STRING }, { paranoid: true })
this.Project.hasMany(this.User)
this.User.hasMany(this.Project)
var self = this
this.sequelize.sync({ force: true }).success(function() {
self.User.bulkCreate([{
username: 'leia'
}, {
username: 'luke'
}, {
username: 'vader'
}]).success(function() {
self.Project.bulkCreate([{
title: 'republic'
},{
title: 'empire'
}]).success(function() {
self.User.findAll().success(function(users){
self.Project.findAll().success(function(projects){
var leia = users[0]
, luke = users[1]
, vader = users[2]
, republic = projects[0]
, empire = projects[1]
leia.setProjects([republic]).success(function(){
luke.setProjects([republic]).success(function(){
vader.setProjects([empire]).success(function(){
leia.destroy().success(function() {
done()
})
})
})
})
})
})
})
})
})
})
it('should not fail with an include', function(done) {
var tableName = ''
, ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier
, escape = this.sequelize.queryInterface.QueryGenerator.escape
if(this.Project.tableName) {
tableName = ident(this.Project.tableName) + '.'
}
this.User.findAll({
where: [
tableName + ident('title') + ' = ' + escape('republic')
],
include: [
{model: this.Project}
]
}).success(function(users){
try{
expect(users.length).to.be.equal(1)
expect(users[0].username).to.be.equal('luke')
done()
}catch(e){
done(e)
}
}).error(done)
})
it('should not overwrite a specified deletedAt', function(done) {
var tableName = ''
, ident = this.sequelize.queryInterface.QueryGenerator.quoteIdentifier
if(this.User.tableName) {
tableName = ident(this.User.tableName) + '.'
}
this.User.findAll({
where: [
tableName + ident('deletedAt') + ' IS NOT NULL '
],
include: [
{model: this.Project}
]
}).success(function(users){
try{
expect(users.length).to.be.equal(1)
expect(users[0].username).to.be.equal('leia')
done()
}catch(e){
done(e)
}
}).error(done)
})
})
})
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!