Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed several issues and added in a spec for saving records with no p…

…rimary keys.
  • Loading branch information...
commit a08d1ca46068888c2960c1097ad57cf26467c911 1 parent 7287f33
Daniel Durante authored
Showing with 26 additions and 9 deletions.
  1. +8 −8 lib/dao-factory.js
  2. +18 −1 spec/dao.spec.js
16 lib/dao-factory.js
View
@@ -151,11 +151,11 @@ module.exports = (function() {
if (!options.include[daoName]) {
options.include[daoName] = this.getAssociationByAlias(daoName).target
}
- }.bind(this))
- }
+ }.bind(this));
- // whereCollection is used for non-primary key updates
- this.options.whereCollection = optcpy.where || undefined;
+ // whereCollection is used for non-primary key updates
+ this.options.whereCollection = options.where || undefined;
+ }
return this.QueryInterface.select(this, this.tableName, options, { type: 'SELECT', hasJoin: hasJoin })
}
@@ -217,14 +217,14 @@ module.exports = (function() {
if (!options.include[daoName]) {
options.include[daoName] = this.getAssociationByAlias(daoName).target
}
- }.bind(this))
+ }.bind(this));
+
+ // whereCollection is used for non-primary key updates
+ this.options.whereCollection = options.where || undefined;
}
options.limit = 1
- // whereCollection is used for non-primary key updates
- this.options.whereCollection = optcpy.where || undefined;
-
return this.QueryInterface.select(this, this.tableName, options, { plain: true, type: 'SELECT', hasJoin: hasJoin })
}
19 spec/dao.spec.js
View
@@ -19,9 +19,17 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
touchedAt: { type: DataTypes.DATE, defaultValue: DataTypes.NOW },
aNumber: { type: DataTypes.INTEGER }
})
+
+ self.HistoryLog = sequelize.define('HistoryLog', {
+ someText: { type: DataTypes.STRING },
+ aNumber: { type: DataTypes.INTEGER },
+ aRandomId: { type: DataTypes.INTEGER }
+ })
},
onComplete: function() {
- self.User.sync({ force: true }).success(done)
+ self.User.sync({ force: true }).success(function(){
+ self.HistoryLog.sync({ force: true }).success(done)
+ })
}
})
})
@@ -67,6 +75,15 @@ describe(Helpers.getTestDialectTeaser("DAO"), function() {
done()
})
})
+
+ it('saves a record with no primary key', function(done){
+ this.HistoryLog.create({ someText: 'Some random text', aNumber: 3, aRandomId: 5 }).success(function(log) {
+ log.updateAttributes({ aNumber: 5 }).success(function(newLog){
+ expect(newLog.aNumber).toEqual(5)
+ done()
+ })
+ })
+ })
})
describe('toJSON', function toJSON() {
Please sign in to comment.
Something went wrong with that request. Please try again.