JSONAPI filter for reference field by null value OR by string

Created on 21 September 2020, over 4 years ago
Updated 14 April 2025, 12 days ago

Problem/Motivation

Once https://www.drupal.org/project/drupal/issues/3025372 β†’ was merged I hoped that filtering for reference fields would work correctly.
I'm still not able to select nodes that are NOT tagged with any value OR are tagged with specific value.

Steps to reproduce

Imagine a content type "node_type" with a field: field_reference that is a taxonomy reference.

Doing...
jsonapi/node/node_type?
filter[main][group][conjunction]=OR
filter[condition1][condition][path]=field_reference
filter[condition1][condition][operator]=IS NULL
filter[condition1][condition][memberOf]=main
filter[condition2][condition][path]=field_reference.name
filter[condition2][condition][operator]==
filter[condition2][condition][value]=Test
filter[condition2][condition][memberOf]=main

I would expect to get all nodes that have no tags at all in that field combined with all nodes tagged with "Test" term.

In reality only nodes tagged with Test will be returned.
It seems that two joins are added for node__field_reference table. A LEFT join used to filter data and an INNER join that is used to filter only published taxonomy terms.
That inner join is added only when I filter by value. If I use only the first condition, with IS NULL, the inner join is not added (would be useless).
When that inner join is added all nodes that don't have a tag are excluded.

Is there a way to avoid automatic condition for published terms?
I altered query to remove joins that broke my filtering but I think that first LEFT join should be reused to check term state.

πŸ› Bug report
Status

Active

Version

11.0 πŸ”₯

Component

jsonapi.module

Created by

πŸ‡·πŸ‡΄Romania Cracu

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States dobe

    I just experienced this same issue on commerce_product's trying to filter by IS NULL for a specific relationship field to a commerce product. @cracu #3 code resolved the issue for me... But seems like that is the wrong long term solution. I have found multiple links that relate to this behavior over the past few years some of them are fixed. But appears it may be creeping back in? I am using latest Drupal 10.

Production build 0.71.5 2024