Score:0

How do I query for all the entities for which a multi value field doesn't contain a specific value?

cn flag

I have a multi value field which contains plain text. This is how it looks from the edit form.

screenshot

I want to fetch entities that don't contain the Expired value. How can achieve it?

This is the code I wrote so far.

$query = \Drupal::entityQuery('taxonomy_term')->condition('vid', 'series');
$group = $query->orConditionGroup()
  ->notExists('field_multi_value')
  ->condition('field_multi_value', 'expired', 'NOT IN');
$query->condition($group);
$ids = $query->execute();
Score:0
fr flag

To my knowledge you have to split it into 2 queries, because EntityQuery would still select a taxonomy_term if it has another value that is not expired. No idea if that is a bug or by design (because technically the taxonomy_term has a value that is NOT expired, in your example Sometext).

So the code would look like this:

$unwantedIds = \Drupal::entityQuery('taxonomy_term')
  ->condition('field_multi_value', 'expired')->execute();
$query = \Drupal::entityQuery('taxonomy_term')
  ->condition('tid', $unwantedIds ?: [-1], 'NOT IN');
$ids = $query->execute();
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.