I'm trying to filter a resultset by "IS NULL" operator. this works normally with attributes, but doesn't work if the filter is done by a path to one relationship.

This url works perfectly

/* WORKS */
https://site.url/api/node/myContentType?filter[my-filter][condition][path]=myAttributeField&filter[my-filter][condition][operator]=IS NULL

but this url always get 0 count in return, regardless of real relationship status

/* DOESN'T WORK */
https://site.url/api/node/myContentType?filter[my-filter][condition][path]=myRelationshipField.id&filter[my-filter][condition][operator]=IS NULL

Funny thing is that instead, the "IS NOT NULL" operator works with relations:

/* WORKS */
https://site.url/api/node/myContentType?filter[my-filter][condition][path]=myRelationshipField.id&filter[my-filter][condition][operator]=IS NOT NULL

Comments

andsigno82 created an issue. See original summary.

gabesullice’s picture

Project: JSON:API » Drupal core
Version: 8.x-2.x-dev » 8.9.x-dev
Component: Code » ajax system
Issue tags: +API-First Initiative

Moving to the Drupal core issue queue. The 2.x branch of JSON:API is no longer maintained.

gabesullice’s picture

Component: ajax system » jsonapi.module
Status: Active » Closed (duplicate)
Related issues: +#3025372: [regression] Impossible to filter for resources with an empty relationship object in JSON:API 2.x
/* DOESN'T WORK */
https://site.url/api/node/myContentType?filter[my-filter][condition][path]=myRelationshipField.id&filter[my-filter][condition][operator]=IS NULL

Under the hood, this filter is saying "give me all instances of myContentType that reference an entity with an empty UUID". An empty result set is "correct" in that case, since you don't have any content that references other content without an ID. All content has an ID, if it exists.

What you really need to be able to do is filter for an empty relationship. I'm pretty sure that this is a duplicate of #3025372: [regression] Impossible to filter for resources with an empty relationship object in JSON:API 2.x. Therefore, I'm going to close this issue as such. If you think otherwise, feel free to reopen.

The linked issue needs someone to reroll the patch for the 8.9.x branch of Drupal core and return it to RTBC status.