Permalink
Browse files

Updated all other occurrences of onSave

  • Loading branch information...
1 parent 4de3702 commit 2be52f5956ef0fb1a13a340cb1c870d455aa2a34 Will Brady committed Dec 13, 2012
Showing with 17 additions and 8 deletions.
  1. +4 −2 README.md
  2. +2 −1 examples/webapp/models/blog.js
  3. +11 −5 lib/connection.js
View
@@ -582,19 +582,21 @@ __Example__
});
<a name="modelOnSave" />
-### Model.onSave(obj)
+### Model.onSave(obj, callback)
If preset this function will be called when an update or save occures. You would typically create this method
in your model file.
__Arguments__
* obj - The object or partial object, in the case of [update](#modelUpdate), being saved.
+ * callback() - The callback to be called when the onSave is complete
__Example__
- Person.onSave = function(obj) {
+ Person.onSave = function(obj, callback) {
obj.lastUpdated = new Date();
+ callback();
};
<a name="modelOnLoad" />
@@ -13,6 +13,7 @@ module.exports = Blog = persist.define("Blog", {
.hasOne(Category)
.hasMany(Keyword, { through: "blogs_keywords" });
-Blog.onSave = function(obj) {
+Blog.onSave = function(obj, callback) {
obj.lastUpdated = new Date();
+ callback();
}
View
@@ -133,14 +133,20 @@ var Connection = Class.extend({
},
updatePartial: function(model, id, data, callback) {
- var self = this;
+ function doOnSave(callback) {
+ if (model.onSave) {
+ return model.onSave(data, callback);
+ }
- if (model.onSave) {
- model.onSave(data);
+ callback();
}
- var sqlAndValues = this.driver.getUpdatePartialSql(model, id, data);
- this._runSql(sqlAndValues.sql, sqlAndValues.values, callback);
+ var self = this;
+
+ doOnSave(function() {
+ var sqlAndValues = this.driver.getUpdatePartialSql(model, id, data);
+ this._runSql(sqlAndValues.sql, sqlAndValues.values, callback);
+ });
},
chain: function(tasks, chainCallback) {

0 comments on commit 2be52f5

Please sign in to comment.