Include Query is returning the whole object instead the specific attributes

Hi there, I am trying to use Include to bring some specific data from the pointer, but always brings all the object like if I were using .includeAll() or include('*'), Class Country has a pointer to Currency (Column name: currencyId), I want to include just the name of the currency.

Using JS SDK, last version of Parse, using Postgres, hosted on ubuntu.

findAllCountries() {
      const query = new Parse.Query('Country')
      query.include('currencyId.name')
      query
        .findAll()
        .then((payload) => {
          this.countries = payload.map((data) => data.toJSON())
        })
        .catch((error) => {
          console.error('error', error)
        })
    }

Image of the country class.

You are seeing the correct functionality. includeAll is for including all objects pointed to at the first level and will include all of the respective object fields.

include - Use on Pointer columns to return the full object

You can use exclude to get what you want

exclude - Exclude specific fields from the returned query

yep, I am trying to retrieve only one attribute/key/column from the pointer/related table (currency)

the docs state that can be specified which keys to get…

Includes nested Parse.Objects for the provided key. You can use dot notation to specify which fields in the included object are also fetched.

You can include all nested Parse.Objects by passing in ‘*’. Requires Parse Server 3.0.0+

query.include(’*’);

Testing now, I see if I do not use query.include, currencyId returns the “pointer”


If I use query.include('WHATEVER'), doesn’t matter what I write inside, *, ‘currencyId’, ‘currencyId.name’, ‘banana’, ALWAYS returns the whole object ???

It sounds like you want to use keys not include from the documentation link I sent:

keys - Restrict the fields returned by the query

This is select in the JS SDK:

http://parseplatform.org/Parse-SDK-JS/api/3.4.2/Parse.Query.html#select

mmm… If I use query.select('currencyId.name') only returns the name of the currency but not the parent data (country)

It has to be the include (I think…) :thinking::thinking:, maybe in the REST api the ‘keys’ are the correct one

What server version are you using? You have to make sure your server is new enough, >= 5.0.0 to have the fixes I applied:

I am using
├── [email protected]
├── [email protected]

this is the content of the package.json file inside parse-server folder…

  "dependencies": {
    "parse-server": "^5.2.1"
  }

How can I check properly the version I am running? I tried parse-server -v but throws error: unknown option

I am using Postgres, maybe works on Mongo but not on Postgres?? :thinking::man_shrugging:

It should work fine on Postgres as that’s what I use and Mongo and Postgres go through the same test suite for query (for the most part)

It has to be the include (I think…) :thinking::thinking:, maybe in the REST api the ‘keys’ are the correct one

You can try a combination of select and include.

If you think there might be an issue, you can try to add a test case similar to:

If it fails, you should open up an issue on the server. Here’s directions for running tests on Postgres locally:

You can look here for more guidance on testing and opening PR’s:

Hi Corey, I really have no idea about testing (and maybe probably will never cross that bridge :man_facepalming:), I am very noob in all this stuff, but I still thinking that maybe this is a bug??
I will come back to this later in the future and figure it out a solution
(I used another approach to my use case this time…)

I think see where the confusion is after testing myself.

The confusion here is that the . notation specifies

You can use dot notation to specify which fields in the included object are also fetched.

This means that you can also include to query any other pointers within that included 2nd level object that you have in the query.

So if your currencyId object had a pointer to a, for example, a businessId object. all the info of the businessId object will also be included in the query by doing

query.include('currencyId.businessId')

Include(keys) doesn’t work the way you posted it originally here where it only returns the specific column you dot notated.

Hi Jayson, that makes more sense… my english is :poop: and I missunderstood the docs…

Maybe we can have someone here suggest a better way of having that line in the docs and we can do a PR.

1 Like

I think I read somewhere that they wanted to merge the API reference inside the Docs or something like that… I was editing the Documentation a couple of weeks ago to update/fix/add small things, I was tempted to move the API Reference into the Docs but I have very little knowledge about Parse to get involved in this task…
maybe for some devs the docs are ok, but for noobs it would be great more examples and so on… so maybe in the future if I become a semi-expert :sweat_smile: in parse I can improve the docs…

yeah the team are planning to make some fixes to the docs system. But we should still make small important PR’s here and there. Overhauling the docs is gonna take some time.