Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 293770

Add a way to query multi-valued entity fields for a NOT IN value

$
0
0

If I have a multi-valued fields, say 'tags', then AFAICT an entity query can't find me entities which do not have the tag ID 123 in that field.

This doesn't work:

  $query = \Drupal::service('entity_type.manager')->getStorage('node')->getQuery()
    ->condition('tags', 123, '<>');
  $ids = $query->execute();

It's possible to do this in SQL by joining to the field table with the field value in the JOIN clause, and then filtering out.


SELECT * FROM node n
LEFT JOIN node__tags t ON n.nid = t.entity_id AND t.value = 123
WHERE t.value IS NULL

Is this something that could be added to entity queries?


Viewing all articles
Browse latest Browse all 293770

Trending Articles