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

Commit 27b88487 by Sascha Depold

use Model.find to reload a model instance

1 parent efe24074
Showing with 22 additions and 1 deletions
...@@ -159,7 +159,28 @@ module.exports = (function() { ...@@ -159,7 +159,28 @@ module.exports = (function() {
* @return {Object} A promise which fires `success`, `error`, `complete` and `sql`. * @return {Object} A promise which fires `success`, `error`, `complete` and `sql`.
*/ */
DAO.prototype.reload = function() { DAO.prototype.reload = function() {
return this.QueryInterface.reload(this, this.__factory.tableName); var where = [
this.QueryInterface.QueryGenerator.addQuotes(this.__factory.tableName) + '.' + this.QueryInterface.QueryGenerator.addQuotes('id')+'=?',
this.id
]
return new Utils.CustomEventEmitter(function(emitter) {
this.__factory.find({
where: where,
limit: 1,
include: this.__eagerlyLoadedOptions || []
})
.on('sql', function(sql) { emitter.emit('sql', sql) })
.on('error', function(error) { emitter.emit('error', error) })
.on('success', function(obj) {
for (var valueName in obj.values) {
if (obj.values.hasOwnProperty(valueName)) {
this[valueName] = obj.values[valueName]
}
}
emitter.emit('success', this)
}.bind(this))
}.bind(this)).run()
} }
/* /*
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!