I need to select some entities that have a certain field (user reference) empty or that field does not contain the current user as a reference.
I tried this, it works ok if the field is empty or if the field contains exactly one value. For multiple values it displays a wrong output:
$query = $this->entityTypeManager()->getStorage('my_entity_type')->getQuery(); $group = $query->orConditionGroup()->notExists("my_field")->condition("my_field", \Drupal::currentUser()->id(), "<>"); $query->condition($group); $query->condition("type", "my_bundle_id"); $ids = $query->sort(...)->execute();
Any thoughts on how to make this work?