Score:0

Entity field condition with "Not Contain" target_id for field multiple values

in flag

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

Kevin avatar
in flag
Did you try <> or NOT IN?
mr.Thi avatar
in flag
I tried <>, and NOT IN. both not worked.
4uk4 avatar
cn flag
This is not possible with joined tables. See https://drupal.stackexchange.com/questions/188969/how-to-use-entityquery-to-select-if-a-multiple-value-entityreference-field-does
mr.Thi avatar
in flag
Thanks @4k4 . seem like I should create a new field in the entity E to check for the condition.
4uk4 avatar
cn flag
The simplest method would be two queries subtracted with array_diff().
mr.Thi avatar
in flag
@4k4, Thanks. actually, I made it worked with 2 queries as you said before asking this question. but I hope that some where like %delta solution work also. but with your comfirmation, I know it's not available at the moment.
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.