Change record status: 
Project: 
Introduced in branch: 
8.7.x
Introduced in version: 
8.7.0
Description: 

When writing a database query, there are use cases when, based on various conditions, the query needs to be "nullified" in order to return an empty result. This could be accomplished by adding a condition that always evaluates to FALSE (for example 1 <> 1).

However, this condition could be added to a query in two ways:

1) using ->where('1 <> 1')
2) using ->condition('1 <> 1')

The second example is incorrect and not supported by Drupal's database abstraction layer, because the $field argument of the condition() method should not be an expression.

To prevent incorrect usages like the one above, a new alwaysFalse() helper method has been added to \Drupal\Core\Database\Query\ConditionInterface.

Code example:

\Drupal::database()->select('example_table', 'et')
  ->fields('et', ['name'])
  ->condition('example_column', 27)
  ->alwaysFalse()
  ->execute()->fetchCol();
Impacts: 
Module developers