directus/directus

`_some` operator limited to top-level relations prevents complex nested filtering

Open

#25,403 创建于 2025年7月3日

在 GitHub 查看
 (6 评论) (4 反应) (0 负责人)TypeScript (3,505 fork)batch import
Help WantedHigh ImpactImprovementLow Reach

仓库指标

Star
 (25,193 star)
PR 合并指标
 (平均合并 10天 11小时) (30 天内合并 99 个 PR)

描述

Describe the Bug

The _some operator is currently restricted to top-level relational alias fields only, which prevents filtering on nested many-to-many relationships that require AND logic on the same nested entity.

When attempting to use _some in deeper relation chains, the following error occurs:

"_some" can only be used with top level relational alias field.

Origin of the Error

To Reproduce

Data Structure:

  • meetings (collection)
  • agenda_items (o2m relation from meetings)
  • topic_matches (m2m relation from agenda_items to topics)

Desired Query:Find meetings that have agenda items addressing BOTH topic1 AND topic2 on the same agenda item.

Attempted Filter:

{
  "filter": {
    "agenda_items": {
      "_and": [
        { 
          "topic_matches": { 
            "_some": { "topic_id": { "_eq": "topic1" } } 
          } 
        },
        { 
          "topic_matches": { 
            "_some": { "topic_id": { "_eq": "topic2" } } 
          } 
        }
      ]
    }
  }
}

Error Result:

Invalid query. "_some" can only be used with top level relational alias field.

Expected Behavior

The query should work and return meetings where at least one agenda item covers both specified topics.

Current Workaround

Currently requires multiple API calls:

  1. Query agenda_items with the nested filter
  2. Group results by meeting
  3. Query meetings using the IDs from step 2

This approach is inefficient and increases complexity.

Workarounds that do not work:

  • Using _in -> resulting in OR query,
  • Using CSV or JSON for the topic tags -> they are not filterable
  • Omitting _some from the query -> returns empty result (see related issue)

Additional Use Cases

This limitation becomes especially apparent, when using some kind of tag system and finding an item based on its children's tags.

  1. Finding festivals with bands tagged both "metal" AND "family-friendly"
  2. Finding documents created by users with both "team-leader" AND "marketing" permissions
  3. Finding meetings with agenda items covering both "hiring" AND "development" topics

Related Issues

directus/directus#18863

Directus Version

11.9.2

Hosting Strategy

Self-Hosted (Docker Image)

Database

mysql 8

贡献者指南