Updated: Comment #N

Problem/Motivation

Drupal\Core\Entity\Query\QueryInterface::exists() currently says "Queries for the existence of a field.".

But that's misleading, what we want to query for is the field value and that might not exist, aka be NULL.

Putting in the documentation component for now, as I'm not sure how to write it.

Proposed resolution

Remaining tasks

User interface changes

API changes

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Ah, obviously, the same applies to notExists()

dawehner’s picture

Issue tags: +Novice

.

jhodgdon’s picture

Title: Improve documentation for Drupal\Core\Entity\Query\QueryInterface::exists() » Fix documentation for Drupal\Core\Entity\Query\QueryInterface::exists()

It looks like the documentation also would need to be updated on the same methods on Drupal\Core\Entity\Query\ConditionInterface as well.

The code that is being executed in the classes that implement this is something like:

return $this->condition($field, NULL, 'IS NOT NULL', $langcode);

I think it can be documented to say:

Queries for a non-NULL value on a field.

and for notExists:

Queries for an empty field (not filled in or NULL value).

(Is that correct on notExists? Not sure how to word it.)

I changed the issue title slightly as well because I think the documentation for exists() is actually completely incorrect, not just misleading.

Berdir’s picture

Yes, empty and not empty might make sense, in IRC, @chx actually first thought the method is isEmpty() instead of exists(), so that is close to the meaning.

Null might be a bit problematic because this is supposed to be storage backend agnostic. The SQL Condition interface actually uses isNull() for this method, but if you use MongoDB or something other than a relational database, references to NULL or "IS NULL" might not be true. Maybe something like "For the database implementation, this is interpreted as IS NULL/IS NOT NULL" could be added to the docblock, as people might be searching for NULL in there (I did).

jhodgdon’s picture

I was thinking of "NULL value" in the PHP sense here, rather than the SQL sense, as in someone programmatically put NULL in for a field value... but probably saying 'empty field (not filled in)' would cover that well enough.

sandykadam’s picture

Status: Active » Needs review
FileSize
896 bytes

Please check attached patch if the wording makes sense.

Berdir’s picture

As mentioned above, I am wondering if it would make sense to move NULL out of the main description and instead have a second line that says "For the SQL backend, this maps to an IS NULL/IS NOT NULL condition".

But I'm fine if @jhodgdon prefers this.

jhodgdon’s picture

Status: Needs review » Needs work

I agree with Berdir. Let's take any mention of NULL out of the descriptions for these methods. So for the latest patch, I would just take out the stuff in () at the end of the descriptions.

sandykadam’s picture

@jhodgdon @Berdir Updated patch as per your suggestion.

Thanks,

sandykadam’s picture

Status: Needs work » Needs review
FileSize
855 bytes

@jhodgdon @Berdir Updated patch as per your suggestion.

Thanks,

jhodgdon’s picture

Status: Needs review » Fixed

Thanks! Looks good, committed to 8.x.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.