Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

Query Collection by array that contains an object with relation to a specific ID

default discord avatar
robink047012 months ago

Heyja, I want to query for an object inside of a collection that has a specific entry in a list, that than has a relation to another item by id. Currently I have set the query like this:

{{base_url}}/api/products?where[shops.data.id][equals]={myid}

if I use a custom field like title or something else it works fine, but when using the auto generated id field, I receive an error

Query Error

with message

The following path cannot be queried: id

how is that supposed to work?



Answer: you can query by id when you dont define the ID attribute as query field. Instead of querying

where[shops.data.id][equals]={id}

you can query for

where[shops.data][equals]={id}

and it will look up in the id field automatically

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.