vadimdemedes / mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
1.38k stars 90 forks source link

Alterative to old middleware `create` hooks example #209

Open wesleycoder opened 6 years ago

wesleycoder commented 6 years ago

I'm struggling trying to get a clean solution for the create hook from previous version.

Before if we wanted to make any modification to the data before creating the instance on the model we could follow the example here but in this version it is not clear what should be the solution for it.

I've looked into the examples of middlewares here but could not understand how it should work.

I think the documentation on Readme.md should clarify this a little bit more.

How could I make the same thing that the old docs describe since the configure method is not being called anymore?

wesleycoder commented 6 years ago

I'm currently working on something like:

export class Player extends Model {
  constructor (data) {
    super(data)
    if (!this.isSaved()) {
      this.set('password', this._cryptPassword(this.get('password')))
    }
  }
  //...
}

Is this a good way of doing it or using middlewares would be a better approach?