`_some` operator limited to top-level relations prevents complex nested filtering
#25,403 创建于 2025年7月3日
仓库指标
- 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.
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:
- Query
agenda_itemswith the nested filter - Group results by meeting
- Query
meetingsusing 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
_somefrom 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.
- Finding festivals with bands tagged both "metal" AND "family-friendly"
- Finding documents created by users with both "team-leader" AND "marketing" permissions
- 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