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

Commit 6d3202df by Mick Hansen

Fix hooks

1 parent 2736e77c
Showing with 8 additions and 11 deletions
...@@ -315,7 +315,7 @@ module.exports = (function() { ...@@ -315,7 +315,7 @@ module.exports = (function() {
} }
if (self.__options.timestamps) { if (self.__options.timestamps) {
self.dataValues[updatedAtAttr] = values[updatedAtAttr] = ( values[updatedAtAttr] = (
( (
self.isNewRecord self.isNewRecord
&& !!self.daoFactory.rawAttributes[updatedAtAttr] && !!self.daoFactory.rawAttributes[updatedAtAttr]
...@@ -325,14 +325,15 @@ module.exports = (function() { ...@@ -325,14 +325,15 @@ module.exports = (function() {
: Utils.now(self.sequelize.options.dialect)) : Utils.now(self.sequelize.options.dialect))
if (self.isNewRecord && !values[createdAtAttr]) { if (self.isNewRecord && !values[createdAtAttr]) {
self.dataValues[createdAtAttr] = values[createdAtAttr] = ( values[createdAtAttr] = (
( (
!!self.daoFactory.rawAttributes[createdAtAttr] !!self.daoFactory.rawAttributes[createdAtAttr]
&& !!self.daoFactory.rawAttributes[createdAtAttr].defaultValue && !!self.daoFactory.rawAttributes[createdAtAttr].defaultValue
) )
? self.daoFactory.rawAttributes[createdAtAttr].defaultValue ? self.daoFactory.rawAttributes[createdAtAttr].defaultValue
: Utils.now(self.sequelize.options.dialect)) : values[updatedAtAttr]
} )
}
} }
var query = null var query = null
...@@ -340,7 +341,6 @@ module.exports = (function() { ...@@ -340,7 +341,6 @@ module.exports = (function() {
, hook = '' , hook = ''
if (self.isNewRecord) { if (self.isNewRecord) {
self.isDirty = false
query = 'insert' query = 'insert'
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, options] args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, options]
hook = 'Create' hook = 'Create'
...@@ -351,8 +351,6 @@ module.exports = (function() { ...@@ -351,8 +351,6 @@ module.exports = (function() {
identifier = self.__options.whereCollection; identifier = self.__options.whereCollection;
} }
self.isDirty = false
query = 'update' query = 'update'
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, identifier, options] args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, identifier, options]
hook = 'Update' hook = 'Update'
...@@ -375,12 +373,11 @@ module.exports = (function() { ...@@ -375,12 +373,11 @@ module.exports = (function() {
}) })
args[2] = values args[2] = values
//self.set(values, {raw: true})
self.QueryInterface[query].apply(self.QueryInterface, args) self.QueryInterface[query].apply(self.QueryInterface, args)
.proxy(emitter, {events: ['sql', 'error']}) .proxy(emitter, {events: ['sql', 'error']})
.success(function(result) { .success(function(result) {
self.__factory.runHooks('after' + hook, result.values, function(err, newValues) { self.__factory.runHooks('after' + hook, values, function(err, newValues) {
if (!!err) { if (!!err) {
return emitter.emit('error', err) return emitter.emit('error', err)
} }
......
...@@ -1870,7 +1870,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () { ...@@ -1870,7 +1870,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
}) })
describe('#updateAttributes', function() { describe('#updateAttributes', function() {
describe('via deifne', function() { describe('via define', function() {
describe('on success', function() { describe('on success', function() {
describe('with a single hook', function() { describe('with a single hook', function() {
it('should return the user from the callback', function(done) { it('should return the user from the callback', function(done) {
...@@ -1988,7 +1988,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () { ...@@ -1988,7 +1988,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
User.sync({ force: true }).success(function() { User.sync({ force: true }).success(function() {
User.create({username: 'Cheech', mood: 'sad'}).success(function(user) { User.create({username: 'Cheech', mood: 'sad'}).success(function(user) {
user.updateAttributes({username: 'Chong'}).success(function(user) { user.updateAttributes({username: 'Chong'}).done(function(err, user) {
expect(user.username).to.equal('Chong') expect(user.username).to.equal('Chong')
expect(user.mood).to.equal('happy') expect(user.mood).to.equal('happy')
expect(beforeHook).to.be.true expect(beforeHook).to.be.true
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!