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.