Permalink
Browse files

Added current connection as param passed to onSave

  • Loading branch information...
1 parent 2be52f5 commit acc903c148edb22f0d830adbf42f6ee821c066a7 Will Brady committed Dec 13, 2012
Showing with 8 additions and 7 deletions.
  1. +3 −2 README.md
  2. +1 −1 examples/webapp/models/blog.js
  3. +4 −4 lib/connection.js
View
@@ -582,19 +582,20 @@ __Example__
});
<a name="modelOnSave" />
-### Model.onSave(obj, callback)
+### Model.onSave(obj, connection, 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.
+ * connection - The connection persist is currently using to do the save
* callback() - The callback to be called when the onSave is complete
__Example__
- Person.onSave = function(obj, callback) {
+ Person.onSave = function(obj, connection, callback) {
obj.lastUpdated = new Date();
callback();
};
@@ -13,7 +13,7 @@ module.exports = Blog = persist.define("Blog", {
.hasOne(Category)
.hasMany(Keyword, { through: "blogs_keywords" });
-Blog.onSave = function(obj, callback) {
+Blog.onSave = function(obj, connection, callback) {
obj.lastUpdated = new Date();
callback();
}
View
@@ -83,7 +83,7 @@ var Connection = Class.extend({
function doOnSave(callback) {
if (obj._getModel().onSave) {
- return obj._getModel().onSave(obj, callback);
+ return obj._getModel().onSave(obj, self, callback);
}
callback();
@@ -135,7 +135,7 @@ var Connection = Class.extend({
updatePartial: function(model, id, data, callback) {
function doOnSave(callback) {
if (model.onSave) {
- return model.onSave(data, callback);
+ return model.onSave(data, self, callback);
}
callback();
@@ -144,8 +144,8 @@ var Connection = Class.extend({
var self = this;
doOnSave(function() {
- var sqlAndValues = this.driver.getUpdatePartialSql(model, id, data);
- this._runSql(sqlAndValues.sql, sqlAndValues.values, callback);
+ var sqlAndValues = self.driver.getUpdatePartialSql(model, id, data);
+ self._runSql(sqlAndValues.sql, sqlAndValues.values, callback);
});
},

0 comments on commit acc903c

Please sign in to comment.