mongoose-lifecycle icon indicating copy to clipboard operation
mongoose-lifecycle copied to clipboard

feature request: afterCreate

Open 0xgeert opened this issue 12 years ago • 2 comments

Consider the use-case where a model instance needs to do some initialization DIRECTLY after it has been created, based on the properties that particular instance is created with.

This would enable controllers to interact with the just created model instance, while being able to rely on the logic defined in afterCreate to have fired.

As of now, there's no hook to support this afaik. (e.g; pre(init) only works on the init of a schema not a schema instance).

It would be great if this could somehow be supported.

Best, Geert-Jan

0xgeert avatar Jun 25 '12 13:06 0xgeert

I think the feature you're asking for is Plugins: http://mongoosejs.com/docs/plugins.html

fzaninotto avatar Jun 25 '12 21:06 fzaninotto

@gbrits: This is handled by the mongoose-lifecycle plugin: https://github.com/fzaninotto/mongoose-lifecycle

robbrit avatar Dec 30 '12 22:12 robbrit