-
Notifications
You must be signed in to change notification settings - Fork 74
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
Suggested pattern to create a multi model service #86
Comments
@zusamann With the official database adapters, a service can be setup with a single model. Model relationships happen at the model level, and the service interface stays purely unaware of them. The second example isn't a good idea with Feathers, but you can possibly make the first work. Once you have created the services, you can reference them by using var commonHooks = {
before: {},
after: {}
};
Object.keys(models).map(key => app.service(`/api/${key}`).hooks(commonHooks)); |
Okay makes sense, I guess it's more about the mental modeling of a rest service, treating each of the db resource as a separate service does seem like a better idea. The approach of a single service for the entire database might make more sense with something like graphql. |
Cool. I'm going to close this. Please reopen if you feel like there's something more to discuss. |
This may be helpful. I used two endpoints and separate hooks on the same service:
Not exactly two services on the same model, but addresses the include issue. |
I have multiple models so I thought I could add a service for each of them. Like so:
But this seems like an inelegant approach if I want to have consistent hooks and other behavior for all of them.
I've looked at another approach which generates a service at the time of a request:
The above doesn't seem to work actually, but the conceptual point stands. Even with this approach it's not very clear how to attach events to this freshly created temp instance of a service. Not even sure if the app will retain all these services or clear them out after a single usage. Plus it might not be very performant either.
I guess what I'm looking for is a parent service that can modularly connect to various models and provides a consistent surface like any other feathers service.
The text was updated successfully, but these errors were encountered: