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

$populate enhancement #149

Closed
evgenyboxer opened this issue Nov 10, 2016 · 2 comments
Closed

$populate enhancement #149

evgenyboxer opened this issue Nov 10, 2016 · 2 comments

Comments

@evgenyboxer
Copy link

Hey,

I really like using $populate (sometimes, I prefer that over the populate hook).
One downside I found is that I couldn't pass multiple populate statements.

Here's how you could query:

query: {
  $populate: {
    children: [
      { path: 'colA', populate: { path: 'fieldA' } },
      { path: 'colB', populate: { path: 'fieldB' } },
    ],
  },
},

and the service could look like:

// Handle $populate
if (filters.$populate) {
  if (filters.$populate.children) {
    filters.$populate.children.forEach((populate) => q.populate(populate));
  } else {
    q.populate(filters.$populate);
  }
}

Thoughts on this?

@marshallswain
Copy link
Member

marshallswain commented Nov 10, 2016

@evgenyboxer Good idea! Why not use an array directly?

query: {
  $populate: [
    { path: 'colA', populate: { path: 'fieldA' } },
    { path: 'colB', populate: { path: 'fieldB' } },
  ]
},

and

// Handle $populate
if (filters.$populate) {
  if (Array.isArray(filters.$populate)) {
    filters.$populate.forEach((populate) => q.populate(populate));
  } else {
    q.populate(filters.$populate);
  }
}

Would that work?

@daffl daffl closed this as completed Dec 3, 2017
@olaferlandsen
Copy link

@evgenyboxer Good idea! Why not use an array directly?

query: {
  $populate: [
    { path: 'colA', populate: { path: 'fieldA' } },
    { path: 'colB', populate: { path: 'fieldB' } },
  ]
},

and

// Handle $populate
if (filters.$populate) {
  if (Array.isArray(filters.$populate)) {
    filters.$populate.forEach((populate) => q.populate(populate));
  } else {
    q.populate(filters.$populate);
  }
}

Would that work?

Can you give me a full example of this?
I need allow sub-populate like:

{
    $populate: [
        {
            path: "author",
            populate: [{path: "image"}]
        }
    ]
}

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

4 participants