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

Commit 6d3202df by Mick Hansen

Fix hooks

1 parent 2736e77c
Showing with 7 additions and 10 deletions
......@@ -315,7 +315,7 @@ module.exports = (function() {
}
if (self.__options.timestamps) {
self.dataValues[updatedAtAttr] = values[updatedAtAttr] = (
values[updatedAtAttr] = (
(
self.isNewRecord
&& !!self.daoFactory.rawAttributes[updatedAtAttr]
......@@ -325,13 +325,14 @@ module.exports = (function() {
: Utils.now(self.sequelize.options.dialect))
if (self.isNewRecord && !values[createdAtAttr]) {
self.dataValues[createdAtAttr] = values[createdAtAttr] = (
values[createdAtAttr] = (
(
!!self.daoFactory.rawAttributes[createdAtAttr]
&& !!self.daoFactory.rawAttributes[createdAtAttr].defaultValue
)
? self.daoFactory.rawAttributes[createdAtAttr].defaultValue
: Utils.now(self.sequelize.options.dialect))
: values[updatedAtAttr]
)
}
}
......@@ -340,7 +341,6 @@ module.exports = (function() {
, hook = ''
if (self.isNewRecord) {
self.isDirty = false
query = 'insert'
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, options]
hook = 'Create'
......@@ -351,8 +351,6 @@ module.exports = (function() {
identifier = self.__options.whereCollection;
}
self.isDirty = false
query = 'update'
args = [self, self.QueryInterface.QueryGenerator.addSchema(self.__factory), values, identifier, options]
hook = 'Update'
......@@ -375,12 +373,11 @@ module.exports = (function() {
})
args[2] = values
//self.set(values, {raw: true})
self.QueryInterface[query].apply(self.QueryInterface, args)
.proxy(emitter, {events: ['sql', 'error']})
.success(function(result) {
self.__factory.runHooks('after' + hook, result.values, function(err, newValues) {
self.__factory.runHooks('after' + hook, values, function(err, newValues) {
if (!!err) {
return emitter.emit('error', err)
}
......
......@@ -1870,7 +1870,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
})
describe('#updateAttributes', function() {
describe('via deifne', function() {
describe('via define', function() {
describe('on success', function() {
describe('with a single hook', function() {
it('should return the user from the callback', function(done) {
......@@ -1988,7 +1988,7 @@ describe(Support.getTestDialectTeaser("Hooks"), function () {
User.sync({ force: true }).success(function() {
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.mood).to.equal('happy')
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!