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
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)
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:
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.
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.
Thanks for the description! Very helpful. That query
shouldlook 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.
Okay thanks, but is this working before? or we really don't have feature like this?
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/2199I don't mean to drag up an old issue, but this isn't working for me on v3. I have a collection of
link
, which has a one-to-many relationship with page collections (
simple-page
,
home-page
, etc.) via a
linkedPage
field. If I try to query by
linkedPage.id
, it throws an error with the message
The following path cannot be queried: linkedPage.id
, which makes sense as the API has the
linkedPage
return an object of
{relationTo: string; value: object}
. If I try to query on
linkedPage.relationTo
, it works. However, if I try to query on
linkedPage.value.id
, I get the error again but with
The following path cannot be queried: linkedPage.value.id
. I've also tried
linkedPage.value._status
,
linkedPage._status
and
linkedPage.value.title
(which is a field on the simple page), but none of them work.
Edit: It looks like the nested relationship query works if there is only 1 type relationship, i.e. if
linkedPage
only
allowed
simple-page
, it would be fine. But as it can have other types related to it, the query doesn't work.
Edit 2: Looks like the
value
is the ID, which is why it can't query nested values, even with the
depth
specified appropriately.
Was this ever resolved?
Star
Discord
online
Get dedicated engineering support directly from the Payload team.