Extend a BaseModel with Ottoman

i’d like to use ottoman in my node server.
I was wondering if there is a way to “extend” a base model when i create a model.

What i’d like to do is like extending a base class with generic methods which could be used by every model that extend it. For example, i’d like to add for every model a “created_at” and “update_at” filed, and set them in a pre save function. Or a static function getAll() that return every document related to that model.
Is it possible?
An example could be what Mongoose for MongoDb calls plugins, http://mongoosejs.com/docs/plugins.html.


Hey @spruzzi23,

You can certainly extend the model created by Ottoman just as you would with an object you created yourself! You can do something like this:

var MyModel = ottoman.model(...);
MyModel.prototype.hello = function() {
  console.log('Hello World');

var x = new MyModel();

Cheers, Brett