directus

Directus Insights: query by multiple items from relational variable


I need to solve an issue when querying a collection from a "Global Relational Variable" multiple select.

I have two models, Credential and ActivePlan with the fields below:

| ActivePlan |
+------------+
| id         | (PK)


| Credential   |
+--------------+
| id           | (PK)
| activePlanId | (FK to ActivePlan id)

Then, I need two panels, a Global Relational Variable that selects multiple ActivePlan items and a List that displays all the Credential items for what the activePlanId field matches the IDs selected from the Global Relational Variable panel.

Using the configuration below, I get a GraphQL validation error: (400 Bad Request) Field "_in" is not defined by type "ActivePlan_filter". Did you mean "_and", "_or", or "id"?

enter image description here

enter image description here

I'm breaking my head around this because I use the same exact filter with multiple select between two Global Relational Variable panels, to filter in the second the selected fields from the first, and it works. I tested the previous setup, changing the second panel from a List to a Global Relational Variable, and the query works. What am I missing here?

Useful Context: I installed Directus over an existing database, and I don't manage the schema from Directus. The relational field between Credentials -> Active Plan is configured properly in Directus UI.

Thanks in advance!


Solution

  • I have realized that although Directus is not suggesting me in the UI that I have access to the ID of the Active Plan (this is probably because I installed Directus over an existing database), I can access to it editing the raw filter.

    Updating my filter to reference the ID of the relational field solved the issue with the query and data is filtered properly.

    {
        "_and": [
            {
                "activePlanId": {
                    "id": {
                        "_in": [
                            "{{ activePlanIds }}"
                        ]
                    }
                }
            }
        ]
    }
    

    Once done that, the UI showed the Filter chain in the UI.

    The issue seems to be that with the List panel, we cannot query with the list of selected entities IDs against the relational field. We need to go one level further and reference the ID of the relation.