# ExistsCondition

> Condition that represents EXISTS operator.

[API reference](/docs/api/index.md) › [yii](/docs/api/yii/index.md) › [db](/docs/api/yii/db/index.md) › [conditions](/docs/api/yii/db/conditions/index.md) › ExistsCondition

| class | `yii\db\conditions\ExistsCondition` |
| --- | --- |
| Implements | [`ConditionInterface`](/docs/api/yii/db/conditions/conditioninterface/index.md) |
| Since | 2.0.14 |
| Source | [`framework/db/conditions/ExistsCondition.php`](https://github.com/yiisoft/yii2/blob/22.0/framework/db/conditions/ExistsCondition.php#L21) |

Condition that represents `EXISTS` operator.

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | ExistsCondition constructor. | `ExistsCondition` |
| [`fromArrayDefinition()`](#method-fromArrayDefinition) static | Creates object by array-definition as described in [Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article. | `ExistsCondition` |
| [`getOperator()`](#method-getOperator) |  | `ExistsCondition` |
| [`getQuery()`](#method-getQuery) |  | `ExistsCondition` |

## Method details

### __construct() <span id="method-__construct"></span>

```php
public function __construct(string $operator, yii\db\Query $query)
```

ExistsCondition constructor.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$operator` | `string` | The operator to use (e.g. `EXISTS` or `NOT EXISTS`) |
| `$query` | [`yii\db\Query`](/docs/api/yii/db/query/index.md) | The [`Query`](/docs/api/yii/db/query/index.md) object representing the sub-query. |

### fromArrayDefinition() <span id="method-fromArrayDefinition"></span>

```php
public static function fromArrayDefinition(mixed $operator, mixed $operands): static
```

Creates object by array-definition as described in
[Query Builder – Operator format](/docs/guide/db-query-builder/index.md#operator-format) guide article.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$operator` | `mixed` | Operator in uppercase. |
| `$operands` | `mixed` | Array of corresponding operands |

**Returns**

`static`

**Throws**

- [`InvalidArgumentException`](https://www.php.net/manual/en/class.invalidargumentexception.php): if input parameters are not suitable for this condition

### getOperator() <span id="method-getOperator"></span>

```php
public function getOperator(): string
```

**Returns**

`string`

### getQuery() <span id="method-getQuery"></span>

```php
public function getQuery(): yii\db\Query
```

**Returns**

[`yii\db\Query`](/docs/api/yii/db/query/index.md)