Skip to content
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

Support population one level deep #3

Closed
ekryski opened this issue Oct 25, 2015 · 2 comments
Closed

Support population one level deep #3

ekryski opened this issue Oct 25, 2015 · 2 comments

Comments

@ekryski
Copy link
Member

ekryski commented Oct 25, 2015

It's pretty reasonable, especially when using population inside of the server, to allow populating (ie. joining) directly related tables.

Let's take an example of getting all the blog posts for a user but you also want the comments.

When a GET request is sent to /posts, the unencoded query string syntax should probably be:

{
  userId: 1,
  $populate: ['comments']
}

Which would result in a find on the posts table with a join on comments where posts.id = comments.postId.

Soliciting feedback, as you can also accomplish this with hooks, so maybe it should be left up to the user to implement.

@ekryski ekryski modified the milestone: 1.0 release Oct 25, 2015
@daffl
Copy link
Member

daffl commented Apr 2, 2016

I think we can do this now with the populate hook so I'm going to close this.

@daffl daffl closed this as completed Apr 2, 2016
@thebarndog
Copy link
Member

Yeah you can. I was going to write my own using mongooses populate function but all I ended up having to do was:

userService.after(hooks.populate('posts', {
    service: '/posts'
}))

Works like a charm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants