0

Entity E have a field reference to Taxonomy T with multi value.

E.field_term.value = [
  ['target_id' => 1],
  ['target_id' => 4],
  ['target_id' => 7],
  ['target_id' => 9],
];

How to query the list of Entity E which not contain Term T (term_Id = 7). I expect some thing like this:

$query = $this->entityTypeManager->getStorage('node')->getQuery();
$query->condition('field_term.entity:taxonomy_term.tid', '7', 'NOT CONTAIN');
    

But of course QueryInterface::condition do not accept NOT CONTAIN as operation. Thanks for your help

6
  • Did you try <> or NOT IN?
    – Kevin
    Sep 17, 2021 at 12:36
  • I tried <>, and NOT IN. both not worked.
    – mr.Thi
    Sep 17, 2021 at 14:05
  • This is not possible with joined tables. See drupal.stackexchange.com/questions/188969/…
    – 4uk4
    Sep 17, 2021 at 18:02
  • Thanks @4k4 . seem like I should create a new field in the entity E to check for the condition.
    – mr.Thi
    Sep 18, 2021 at 14:20
  • The simplest method would be two queries subtracted with array_diff().
    – 4uk4
    Sep 19, 2021 at 9:32

0

Browse other questions tagged or ask your own question.