-
-
Notifications
You must be signed in to change notification settings - Fork 754
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
We need to support relationships between resources #22
Comments
Yes. That is exactly what I am missing as well. |
We found that pretty tricky to solve because you'll have to somehow model your relationships between services and by doing so you will eventually go down the ORM path (and that's a can of worms at least I personally wouldn't want to touch). What I actually wonder is, if something like: app.use('/users/:userId/posts', postsService); Might even already work (with |
You could also consider following:
app.service('posts', '/users/:userId/posts', postsService) like it is done in https://github.com/visionmedia/express-resource |
app.use(app.settings.env === 'production' ? 'todos/' : 't/', todoService); I'm also not sure when I'd want different URIs in development and production (except for maybe changing the root).
|
app.use(app.settings.env === 'production' ? 'todos/' : 't/', todoService); The problem is that you assume route to be a service name, how should I reference to service in app.lookup(app.settings.env === 'production' ? 'todos/' : 't/') ? |
You could also use the express-alias module. The service names however will (and imho should) stay the same in all cases ( |
So a basic version for associations seems pretty easy to implement as discussed above. Here my suggestion: Definition and use with REST URIs: // Both associations should only work if there is a /users service registered already
app.use('/users', userService)
.use('/posts', postsService)
.use('/accounts', accountService);
// Pass service name in an array
// Calls postsService.findAll({ userId: <userId> })
app.associate('/users/:userId/posts', ['posts']);
// Calls userService.get(<userId>) then calls
// accountService.get(user.account)
app.associate('/users/:userId/account', 'accounts'); For SocketIO: The easiest way is probably this: socket.emit('/users/:userId/posts', { userId: 123 }, function(error, posts) {
}); I understand that socket.emit('/users/123/posts', function(error, posts) {
}); Might look appealing but in reality you'd probably always end up with annoying string concatenation like |
One more addition: In order to not monkey-patch |
@daffl the concept would totally work. For some reason I feel like passing an array for
I think we should totally use |
+1 for |
In order to kick off a plugin ecosystem for Feathers and keeping the core lean I'm thinking of making this (as well as session handling) a separate plugin. So you would do
var feathers = require('feathers');
var associations = require('feathers-associations');
var app = feathers().configure(associations)
.use('/users', userService)
.use('/posts', postsService)
.associate('/users/:userId/posts', ['posts']); |
+1 for this feature! Is there anything I could do to contribute to speed up development of this feature? I like the idea of having Feathers plugins. |
I already refactored the REST provider to make it possible to wrap other services into a middleware externally (it was all within the provider before and not accessible from the outside). So this plugin should happen fairly soon (as well as a 0.3.1 release). |
Oh, that's excellent middleware is already supported then. Thank you. I'd really like to work on the plugin repository. And I just started learning Mocha for Unit Testing; would that be what you'd recommend using? Edit: Edit 2: Edit 3: |
Any progress on this? I have recently release feathers-mongoose-service (https://github.com/Glavin001/feathers-mongoose-service) and would like to also support relationships / associations. I'd be happy to help develop the suggested feathers-associations plugin, however I will need a little guidance as I have not yet figured out how I can wrap custom service methods externally into Feathers, as suggested above. I hope we can get this feature soon! Thank you for an awesome product. |
For those who are following this issue, @daffl has created the associations plugin: https://github.com/feathersjs/associations |
Closing since development has moved to https://github.com/feathersjs/feathers-associations. First version for RESTful associations should be working already. |
what happened to this? feathers association has not been updated since 2 years. |
We have an FAQ item about this at http://docs.feathersjs.com/help/faq.html#how-do-i-return-related-entities |
@daffl All of the links associated with "associations" are dead. Any fresh ones? |
Whoops, sorry, the current link is https://docs.feathersjs.com/faq/readme.html#how-do-i-do-associations, for nested and custom routes it is https://docs.feathersjs.com/faq/readme.html#how-do-i-do-nested-or-custom-routes |
Philosophically speaking, why is |
It is better because it is much easier to create and serialize an object with |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue with a link to this issue for related bugs. |
I should be able to hit a route like
GET /users/:id/posts
and get all the users posts.The text was updated successfully, but these errors were encountered: