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

Commit cfc66e9e by Sascha Depold

Emit the sql event of the find method as well

1 parent 4ac8c613
Showing with 27 additions and 25 deletions
...@@ -52,7 +52,7 @@ module.exports = (function() { ...@@ -52,7 +52,7 @@ module.exports = (function() {
if (this.options.constraints !== false) { if (this.options.constraints !== false) {
this.options.onDelete = this.options.onDelete || 'SET NULL' this.options.onDelete = this.options.onDelete || 'SET NULL'
this.options.onUpdate = this.options.onUpdate || 'CASCADE' this.options.onUpdate = this.options.onUpdate || 'CASCADE'
} }
Helpers.addForeignKeyConstraints(this.target.rawAttributes[this.identifier], this.source, this.target, this.options) Helpers.addForeignKeyConstraints(this.target.rawAttributes[this.identifier], this.source, this.target, this.options)
// Sync attributes and setters/getters to DAO prototype // Sync attributes and setters/getters to DAO prototype
...@@ -87,32 +87,34 @@ module.exports = (function() { ...@@ -87,32 +87,34 @@ module.exports = (function() {
var instance = this var instance = this
return new Utils.CustomEventEmitter(function(emitter) { return new Utils.CustomEventEmitter(function(emitter) {
instance[association.accessors.get]().success(function(oldInstance) { instance[association.accessors.get]()
if (oldInstance) { .success(function(oldInstance) {
oldInstance[association.identifier] = null if (oldInstance) {
oldInstance oldInstance[association.identifier] = null
.save(Utils._.extend({}, options, { oldInstance
fields: [association.identifier], .save(Utils._.extend({}, options, {
allowNull: [association.identifier], fields: [association.identifier],
association: true allowNull: [association.identifier],
})) association: true
.success(function() { }))
if (associatedInstance) { .success(function() {
associatedInstance.set(association.identifier, instance.get(association.sourceIdentifier)) if (associatedInstance) {
associatedInstance.save(options).proxy(emitter) associatedInstance.set(association.identifier, instance.get(association.sourceIdentifier))
} else { associatedInstance.save(options).proxy(emitter)
emitter.emit('success', null) } else {
} emitter.emit('success', null)
}) }
} else { })
if (associatedInstance) {
associatedInstance.set(association.identifier, instance.get(association.sourceIdentifier))
associatedInstance.save(options).proxy(emitter)
} else { } else {
emitter.emit('success', null) if (associatedInstance) {
associatedInstance.set(association.identifier, instance.get(association.sourceIdentifier))
associatedInstance.save(options).proxy(emitter)
} else {
emitter.emit('success', null)
}
} }
} })
}) .proxy(emitter, { events: ['sql'] })
}).run() }).run()
} }
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!