Drupal - EntityQuery condition "is not equal to..."

I found it !

I was not far away, I've just to reverse the last two parameters of the condition.

$query = \Drupal::entityQuery('node')
       ->condition('type', 'order')
       ->condition('field_multiple_choice', 'doe', '!=');
$nids = $query->execute();
$entities = \Drupal::entityManager()->getStorage('node')->loadMultiple($nids);

As the doc says, public function QueryInterface::condition take following arguments :

condition( $field , $value = NULL , $operator = NULL , $langcode = NULL )

It is impossible to check for the existence of entities with field <> value if that field may be null.

Instead, you must use an orCondition to do notExists OR <>:

$query= Drupal::service('entity.query')->get('myentity');
$group = $query->orConditionGroup()
->notExists('my_field')
->condition('my_field', '53', '<>');
$ids = $query->condition($group)->execute();

Tags:

Database

8