I am trying to query all root terms of a hierarchical vocabulary by using: ?filter[parent.0.id]=virtual but it returns no records.

According to https://www.drupal.org/docs/8/modules/jsonapi/core-concepts#virtual the parents value of a root term has the value "virtual" so I would expect it to also work for filtering.

Not sure if this did work before.

CommentFileSizeAuthor
#3 3021137-3.patch1.17 KBwim leers

Comments

dvdzee created an issue. See original summary.

wim leers’s picture

Title: Root level terms with "virtual" parents cannot be filtered » Ability to filter terms by "virtual" parent
Version: 8.x-2.0-rc3 » 8.x-2.x-dev
Category: Bug report » Feature request
Issue tags: +API-First Initiative

Thanks for taking the time to report this! 🙏

I think that's a reasonable expectation, but it would be a new feature. This has never been supported.

wim leers’s picture

StatusFileSize
new1.17 KB

This is not yet passing tests, but something like this is the test coverage we'd want, and which this feature is asking to pass.

gabesullice’s picture

+1

wim leers’s picture

wim leers’s picture

bucefal91’s picture

Hello, guys!

Correct me if I am wrong, but I think we "done-done" here just because the other issue (#3025372: [regression] Impossible to filter for resources with an empty relationship object in JSON:API 2.x) has been resolved.

/jsonapi/taxonomy_term/campaign_goal?filter[alex][condition][path]=parent.id&filter[alex][condition][operator]=IS NULL
yields the correct result to me on a 8.9.3 core, i.e. to fetch the top-most terms you just query for such terms whose parent is NULL.

I think to make this issue entirely resolved, the only thing I would propose additionally is to update the docs pages related to the to state the exact way you can filter things.

arakwar’s picture

Version: 8.x-2.x-dev » 8.x-2.4

I am going to correct you :)

This works when you are logged in, in Drupal 9.4.5. When the request is done by an anonymous user, it's empty.

EDIT : We found a way to make it work. You need to filter by parent.id and leave the value field empty.