Skip to content

Exclude child elements in query results #7030

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

Closed
uzaysan opened this issue Nov 29, 2020 · 5 comments · Fixed by #7242
Closed

Exclude child elements in query results #7030

uzaysan opened this issue Nov 29, 2020 · 5 comments · Fixed by #7242
Labels
state:released Released as stable version state:released-beta Released as beta version type:feature New feature or improvement of existing feature

Comments

@uzaysan
Copy link

uzaysan commented Nov 29, 2020

Is your feature request related to a problem? Please describe.
In parse server we can put parse objects to another parse object. And we can get them with include method.
We also select specific fields from child objects with select method.
But we cannot exclude fields from child object. Lets assume we have Book object. And author field is a pointer to a user. If I want to get author alongside with book object, user object is fully fetched. But If I want to exclude some sensitive fields such as email field, I can't do that. Exclude method only works for Book object. But User objects is ignored.

Describe the solution you'd like
We should be able to exclude unwanted fields from child objects. Here is an example code:

var query = New Parse.Query("Book");
query.include("author");
query.exclude("someBookField","author.email");
...
const results = await.query.find();
//There is no email field in results.

Describe alternatives you've considered
We can convert parse objects to JSON and we can delete the unwanted fields by manually. But this is useless if our main porpouse is save bandwidth costs.

@mtrezza mtrezza transferred this issue from parse-community/Parse-SDK-JS Nov 29, 2020
@mtrezza mtrezza changed the title Make exclude work for child objects Exclude child elements in query results Nov 29, 2020
@mtrezza
Copy link
Member

mtrezza commented Nov 29, 2020

Thanks for this suggestion; initially discussed in Parse Forum.

Would you want to open a PR and create a failing test, so that we can get started to fix this?
You can take a look at the contribution guide for how to set up Parse Server for local debugging.

The basic steps are:

  1. Fork Parse Server and clone repository locally.
  2. Create new branch.
  3. Set-up local debugging for Parse Server as described in the contribution guide.
  4. Look at ParseQuery.spec.js where there is already a test for exclude:
    it('exclude keys (sdk query)', async done => {
    const obj = new TestObject({ foo: 'baz', hello: 'world' });
    await obj.save();
    const query = new Parse.Query('TestObject');
    query.exclude('foo');
    const object = await query.get(obj.id);
    expect(object.get('foo')).toBeUndefined();
    expect(object.get('hello')).toBe('world');
    done();
    });
  5. Add a test for excluding a child element; using the existing tests as guidance. If test fails, it confirms that there is an issue.
  6. Commit the failing test to your branch and submit a pull request. In the PR description add a link to this issue.
  7. Debug the test step-by-step to find out why it fails. It could be in Parse Server and/or the Parse JS SDK.
  8. Add the fix in Parse Server and/or the Parse JS SDK to make the test pass.
  9. Commit the fixes to your branch. This will automatically update the PR you already created.

If you need any guidance please let us know and we'll be glad to support.

@dplewis
Copy link
Member

dplewis commented Mar 10, 2021

@cbaker6 Since you are already looking into exclude can you look into this one?

@mtrezza
Copy link
Member

mtrezza commented May 20, 2021

As discussed in #7390 (comment), the PR for this issue seems to be mixed into PR #7242.

I am glad to see the issue being addressed. Having said that, for future PRs we should try to keep distinct issues and corresponding distinct PRs, unless issues are so intertwined that they cannot be addressed separately. Otherwise PRs blow up in scope and we increase review times, risk of bugs, etc.

@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0-beta.1

@parseplatformorg parseplatformorg added the state:released-beta Released as beta version label Nov 1, 2021
@mtrezza mtrezza added type:feature New feature or improvement of existing feature and removed type:improvement labels Dec 6, 2021
@parseplatformorg
Copy link
Contributor

🎉 This change has been released in version 5.0.0

@parseplatformorg parseplatformorg added the state:released Released as stable version label Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
state:released Released as stable version state:released-beta Released as beta version type:feature New feature or improvement of existing feature
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants