Change record status: 
Project: 
Introduced in branch: 
10.1.x
Introduced in version: 
10.1.0
Description: 

Prior to Drupal 10.1.0, passing an array as the value in a database condition without passing an operator resulted in inconsistent behaviours.

For example
$condition->condition('foobar', [1]);

would work, whilst

$condition->condition('foobar', [1, 2]);

would not.

Starting in Drupal 10.1.0, passing an array for the value with any of the =, >, <, >=, <=, IS NULL or IS NOT NULL operators or no operator will result in an exception.

Impacts: 
Module developers

Comments

serverjohn’s picture

I am not sure where this change happened but it worked before Drupal 11.1.8 and possibly Drupal 11. I got this error and it took me a little to figure it out as I wasn't using an 'IN' operator.

What worked before but doesn't now:

$nid = $node->get('field_entity_reference_field')->getValue();

$query = \Drupal::entityQuery('node')
  ->accessCheck(FALSE);
  ->condition('nid', $nid)
  ->execute();

The getValue returns an array which causes the issue. The fix is to just use the getString function instead.

This works:

$nid = $node->get('field_entity_reference_field')->getString();

$query = \Drupal::entityQuery('node')
  ->accessCheck(FALSE);
  ->condition('nid', $nid)
  ->execute();

I hope this helps someone that is scratching their head.