Like what we’re doing? Star us on GitHub!

Is it possible to query a 3 nested collection?

johnmadrigal_
4 weeks ago
7

I have these collections,



Location Group


Location


Post



Location Group has a value "title" string.


Location has a value "group" which relates to Location Group and "title" string.


Post has a value "location" which relates to Location.



When I'm trying to use dot notation on REST query on Post using location.locationGroup.title, it's not working, but when I use location.title, its working.



PLEASE HELP

  • jacobsfletch
    Payload Team
    4 weeks ago

    @johnmadrigal_ can you paste in your configs? You may I can help you write a query for this, which would look something like this

    ?where[location.group.title][equals]=hello&depth=3

    (depth might be your missing piece)

  • johnmadrigal_
    4 weeks ago

    Hello Jacob, thanks for responding. I am using your sample work name "website-cms" and I also found the same issue with your code.



    This is the repo code:


    https://github.com/payloadcms/website-cms/blob/main/src/collections/Posts.ts

    Can you create a Post record and create a query for "author.photo.alt"? Because in my end, even if I puth depth in the query, it still shows nothing.



    http://localhost:9000/api/posts?where[author.photo.alt][equals]=test&depth=3

    I'm suspecting that it is not allowed to query the 2nd nested collection, which in your code, the photo inside author which is under post.



    That is the exact issue i'm facing in my own payloadcms app.

  • jacobsfletch
    Payload Team
    4 weeks ago

    Thanks for the description! Very helpful. That query

    should

    look like this:

    https://cms.payloadcms.com/api/posts?where[author.photo.alt][equals]=Write%20for%20the%20Community%20Blog%20Image

    but it appears to be broken at the moment 😢



    Go ahead and pull an issue in our repo if you'd like. We'll get this patched up.

  • johnmadrigal_
    4 weeks ago

    Okay thanks, but is this working before? or we really don't have feature like this?

  • jacobsfletch
    Payload Team
    4 weeks ago

    This was working before so once we fix the issue we'll also write tests to prevent future regression.



    Update: this was fixed with

    https://github.com/payloadcms/payload/pull/2199
Open the post
Continue the discussion in Discord
Can't find what you're looking for?
Get help straight from the Payload team with an Enterprise License.Learn More