ensureMyTable(); $subselect = db_select('comment_field_data', 'c'); $subselect->addField('c', 'cid'); $subselect->condition('c.uid', $this->value, $this->operator); $entity_id = $this->definition['entity_id']; $entity_type = $this->definition['entity_type']; $subselect->where("c.entity_id = $this->tableAlias.$entity_id"); $subselect->condition('c.entity_type', $entity_type); $condition = (new Condition('OR')) ->condition("$this->tableAlias.uid", $this->value, $this->operator) ->exists($subselect); $this->query->addWhere($this->options['group'], $condition); } }