Comparing version 0.1.4 to 0.1.5
@@ -15,2 +15,12 @@ --- | ||
## Before create callback | ||
LazyBoy supports a before create callback. It is defined on the model and will be called once when the model is created. | ||
var User = Model('User'); | ||
User.beforeCreate(function (user) { | ||
// do something before create model | ||
}); | ||
Save | ||
@@ -29,3 +39,18 @@ ==== | ||
## Save Callbacks | ||
Before and after save callbacks are supported. They are defined on the model and will be called when each model is saved. | ||
var User = Model('User'); | ||
User.beforeSave(function (user) { | ||
// do something before save model | ||
}); | ||
User.afterSave(function (user) { | ||
// do something after save model | ||
}); | ||
Remove | ||
@@ -40,4 +65,19 @@ ====== | ||
This will remove the model from the database, not getting it back after this! | ||
This will remove the model from the database, no getting it back after this! | ||
## Remove Callbacks | ||
Two callbacks for the `remove` method are supported. | ||
var User = Model('User'); | ||
User.beforeRemove(function (user) { | ||
// do something before removing model | ||
}); | ||
User.afterRemove(function (user) { | ||
// do something after removing model | ||
}); | ||
These are self explanatory and will be called before and after a model has been removed from the database | ||
@@ -41,10 +41,20 @@ --- | ||
Loading Models | ||
Loading Models | ||
============== | ||
The models need to be loaded for LazyBoy to work. This can be done via two ways. The first is to manually require the files where the models are defined and then call `Model.load()` or | ||
keep all the models in a specific folder and point LazyBoy to that directory that contains all your models eg. `Model.load('models')`. Important to note is that LazyBoy always loads the models folder relatively from the base folder that the node app was started from. | ||
The models needs to be loaded for LazyBoy to work. This can be done via two ways. The first is to manually require the files where the models are defined and then call | ||
Model.load() | ||
This is done after all the models have been defined and in the same file as all the models have been defined. This is for very simple use cases. | ||
A better way is to keep all the models in a specific folder and point LazyBoy to that directory. To load the Models then: | ||
Model.load('models') | ||
Important to note is that LazyBoy always loads the models folder relatively from the base folder that the node app was started from. | ||
<br /> | ||
<br /> |
@@ -21,2 +21,3 @@ var Saveable = require('./base').Saveable, | ||
serialised_doc.model_type = self.model_type; | ||
serialised_doc.id = self.id; | ||
@@ -23,0 +24,0 @@ Object.keys(self.schema).forEach(function (key) { |
@@ -5,3 +5,3 @@ { | ||
"description": "A object document mapper for couchdb", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"homepage": "http://garrensmith.com/LazyBoy", | ||
@@ -8,0 +8,0 @@ "repository": { |
@@ -70,3 +70,3 @@ LazyBoy Object Modeller | ||
#Changelog | ||
13 Sep 2011 - Add Id to serialised model | ||
11 Sep 2011 - Add Before And After Remove Callbacks (Donnie Hedin) | ||
@@ -73,0 +73,0 @@ 17 Aug 2011 - Add support for custom methods |
57522
1260