Strapi populate and filter

Hi all

I am execute a query with populate and filter, where Нolding id=1.
How to exclude Region2 ? In it, Holdings is not included in the filter results.

http://localhost:1337/api/regions?populate[0]=holdings&populate[holdings][filters][id][$eq]=1
{
    "data": [
        {
            "id": 1,
            "attributes": {
                "name": "Region1",
                "createdAt": "2022-03-23T03:37:10.648Z",
                "updatedAt": "2022-03-23T03:37:16.333Z",
                "holdings": {
                    "data": [
                        {
                            "id": 1,
                            "attributes": {
                                "name": "Holding1",
                                "createdAt": "2022-03-23T03:36:39.995Z",
                                "updatedAt": "2022-03-23T03:45:24.618Z"
                            }
                        }
                    ]
                }
            }
        },
        {
            "id": 2,
            "attributes": {
                "name": "Region2",
                "createdAt": "2022-03-23T06:12:41.862Z",
                "updatedAt": "2022-03-23T06:12:48.861Z",
                "holdings": {
                    "data": []
                }
            }
        },
        {
            "id": 3,
            "attributes": {
                "name": "Region3",
                "createdAt": "2022-03-25T03:38:38.340Z",
                "updatedAt": "2022-03-25T03:39:08.389Z",
                "holdings": {
                    "data": [
                        {
                            "id": 1,
                            "attributes": {
                                "name": "Holding3",
                                "createdAt": "2022-03-23T03:36:39.995Z",
                                "updatedAt": "2022-03-23T03:45:24.618Z"
                            }
                        }
                    ]
                }
            }
        }
    ],
    "meta": {
        "pagination": {
            "page": 1,
            "pageSize": 25,
            "pageCount": 1,
            "total": 3
        }
    }
}

hello,

I have the same problem, did you solve it?

thx

Is it permissions in the related entity?

It worked for me to do normal filters. In your case you add a [filters][holdings][id][$eq]=1, but I did it with custom endpoint so maybe you want to try that too.

Hi, if I dont misunderstand your question, you’re looking for a way to filter data that has relations and you need them in your response?

You can try it like this:

http://localhost:1337/api/regions?filters[holdings][id][$eq]=1&populate[0]=holdings

I hope i helped :slight_smile: if not i guess at least i tried :smiley:

1 Like