-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Hooks support #27
Comments
Thanks for opening an issue.
Pre and post hooks for what exactly? |
Thanks for responding. What I meant was the equivalent of the middleware in mongoose, or callbacks in Mongoid (where I'm just coming from to Node). |
Oh I see. This hasn't come up before. We don't have models in the sense that you'd change instance data and call a My initial thoughts are;
|
Sorry, I don't quite understand the bit about I'm new to hapi (and indeed Node) but I'm assuming schema validation à la mongoose should be fairly straightforward with Joi in the handler config itself, isn't it? That in fact is reason enough for me to consider this project, because I don't like the idea of introducing another DSL for validation. Re pre/post, I'm still finding my way here but I think it'd be hard to beat the elegance of the lifecycle methods and it would be great if we could natively support them here. |
Meaning when you create a model it doesn't come with a
Not exactly. From the docs you linked to:
As you can see, the native
Take a look at Frame.
I need some more convincing. I'd like to see what having these hooks allows us to do that we can't do without them. |
Thanks for pointing me to Frame, will take a look at it. I can't speak for others, but I've used callbacks variously as utilities to keep my code organised. It's useful to track the lifecycle of an object's creation if I don't have control of where or how it's getting created, as long as there are a few checks or additional things I can do to it or to other models that may be affected by its contents. I've also used it to set some fields to nil/null before saving if they're being received as empty strings from the client, etc (effectively, validation). One may argue that some of these things could and sometimes should be done just before/after the object is being directly saved, but callbacks give me the option of keeping things DRY. Slightly off-topic, how well does HMM deal with nested documents? |
I'm not sure what HMM is. |
I'm surprised you haven't yet thought of an acronym for your project ;) I was trying to figure out from the docs and tests if hapi-mongo-models is designed to play well with (deeply) nested documents out of the box, but couldn't find anything. Admittedly, I haven't yet played with it enough to test that out myself. |
I see now. Haha.
If there are limitations they shouldn't be from this library. The more accurate question to ask is what limitations does mongodb have with nested documents and the same goes for Joi. |
Makes sense, I'll look that up and open another issue if it doesn't work as expected. |
This looks like just the project I was looking for. Joi is awesome and it's great that you're using that.
Do you support pre and post hooks? I couldn't find any references to that in the docs. If not, is it anywhere on the roadmap?
The text was updated successfully, but these errors were encountered: