Skip to content

Commit

Permalink
Merge pull request sequelize#9 from mbroadst/fix-update-logic
Browse files Browse the repository at this point in the history
remove faulty logic in update code
  • Loading branch information
Joel Trost committed Nov 17, 2014
2 parents 24cdc4b + e49c4b0 commit 8fd1005
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 28 deletions.
38 changes: 18 additions & 20 deletions lib/dialects/mssql/query-generator.js
Expand Up @@ -226,30 +226,28 @@ module.exports = (function() {
var query;
attrValueHash = Utils.removeNullValuesFromHash(attrValueHash, false, options);

//very unique case for cascades, i generally don't approve
if(Object.keys(attrValueHash).length === 1 && attributes[Object.keys(attrValueHash)[0]].primaryKey){
this.sequelize.log('Updating a Primary Key is not supported in MSSQL, please restructure your query');
}else{
for(var key in attributes){
var aliasKey = attributes[key].field || key;
if(attributes[key].primaryKey && attrValueHash[aliasKey]){
delete attrValueHash[aliasKey];
}
if(attrValueHash[aliasKey] && attrValueHash[aliasKey].fn){

}
for (var key in attributes) {
var aliasKey = attributes[key].field || key;
if (attributes[key].primaryKey && attrValueHash[aliasKey]) {
delete attrValueHash[aliasKey];
}
if(!Object.keys(attrValueHash).length){
return '';
//return ['SELECT * FROM ', tableName, 'WHERE', this.getWhereConditions(where) + ';'].join(' ');

if (attrValueHash[aliasKey] && attrValueHash[aliasKey].fn) {

}
query = [
SqlGenerator.updateSql(tableName, attrValueHash, attributes),
'WHERE',
this.getWhereConditions(where)
].join(' ') + ';';
}

if (!Object.keys(attrValueHash).length) {
return '';
//return ['SELECT * FROM ', tableName, 'WHERE', this.getWhereConditions(where) + ';'].join(' ');
}

query = [
SqlGenerator.updateSql(tableName, attrValueHash, attributes),
'WHERE',
this.getWhereConditions(where)
].join(' ') + ';';

return query;
},

Expand Down
16 changes: 8 additions & 8 deletions test/dao-factory.test.js
Expand Up @@ -755,13 +755,13 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
where: {username: 'foo'},
defaults: { foo: 'asd' },
transaction: t
}).spread(function(user3) {
if(dialect !== 'mssql'){
expect(user1.isNewRecord).to.be.true
}
}).spread(function(user3) {
if(dialect !== 'mssql'){
expect(user1.isNewRecord).to.be.true
}
expect(user2.isNewRecord).to.be.false
expect(user3.isNewRecord).to.be.false
t.commit().success(function() {
t.commit().success(function() {
done()
})
})
Expand Down Expand Up @@ -1663,7 +1663,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
expect(min1).to.be.not.ok
}
expect(min2).to.equal(5)

t.rollback().success(function(){ done() })
})
})
Expand Down Expand Up @@ -1969,7 +1969,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
} else if (dialect === 'mssql'){
expect(self.UserSpecialSync.getTableName().toString()).to.equal('special.UserSpecials');
expect(UserSpecial.indexOf('INSERT INTO "special.UserSpecials"')).to.be.above(-1)
expect(UserPublic.indexOf('INSERT INTO "UserPublics"')).to.be.above(-1)
expect(UserPublic.indexOf('INSERT INTO "UserPublics"')).to.be.above(-1)
} else {
expect(self.UserSpecialSync.getTableName().toString()).to.equal('`special.UserSpecials`');
expect(UserSpecial.indexOf('INSERT INTO `special.UserSpecials`')).to.be.above(-1)
Expand Down Expand Up @@ -2145,7 +2145,7 @@ describe(Support.getTestDialectTeaser("DAOFactory"), function () {
})
})
})

//mssql is not supported by the sql package
if(dialect !== 'mssql'){
describe("syntax sugar", function() {
Expand Down

0 comments on commit 8fd1005

Please sign in to comment.