# Condition

> Marks a query condition as owned by the soft-delete scope and qualifies its bare column names with a table alias.

[API reference](/docs/api/index.md) › [Soft Delete](/docs/extensions/soft-delete/reference/index.md) › Condition

| final class | `yii2\extensions\softdelete\Condition` |
| --- | --- |
| Extends | [`yii\db\conditions\AndCondition`](/docs/api/yii/db/conditions/andcondition/index.md) » [`yii\db\conditions\ConjunctionCondition`](/docs/api/yii/db/conditions/conjunctioncondition/index.md) |
| Implements | [`yii\db\conditions\ConditionInterface`](/docs/api/yii/db/conditions/conditioninterface/index.md) |
| Source | [`src/Condition.php`](https://github.com/yii2-extensions/soft-delete/blob/main/src/Condition.php#L23) |

Marks a query condition as owned by the soft-delete scope and qualifies its bare column names with a table alias.

## Properties

| Property | Type | Description | Defined by |
| --- | --- | --- | --- |
| <span id="property-expressions"></span>[`$expressions`](/docs/api/yii/db/conditions/conjunctioncondition/index.md#property-expressions) protected | `mixed[]` | Default: `null`. | [`yii\db\conditions\ConjunctionCondition`](/docs/api/yii/db/conditions/conjunctioncondition/index.md) |

## Methods

| Method | Description | Defined by |
| --- | --- | --- |
| [`__construct()`](#method-__construct) | Creates a condition with optional table-alias qualification. | `Condition` |
| <span id="method-fromArrayDefinition"></span>[`fromArrayDefinition()`](/docs/api/yii/db/conditions/conjunctioncondition/index.md#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. | [`yii\db\conditions\ConjunctionCondition`](/docs/api/yii/db/conditions/conjunctioncondition/index.md) |
| <span id="method-getExpressions"></span>[`getExpressions()`](/docs/api/yii/db/conditions/conjunctioncondition/index.md#method-getExpressions) |  | [`yii\db\conditions\ConjunctionCondition`](/docs/api/yii/db/conditions/conjunctioncondition/index.md) |
| <span id="method-getOperator"></span>[`getOperator()`](/docs/api/yii/db/conditions/andcondition/index.md#method-getOperator) | Returns the operator that is represented by this condition class, e.g. `AND`, `OR`. | [`yii\db\conditions\AndCondition`](/docs/api/yii/db/conditions/andcondition/index.md) |
| [`map()`](#method-map) static | Applies the callback to every soft-delete scope inside an `and` condition, recursing into nested `and` operands. | `Condition` |
| [`withAlias()`](#method-withAlias) | Returns a new scope with the original condition qualified with the given table alias. | `Condition` |

## Method details

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

```php
public function __construct(array<array-key, mixed> $condition, string|null $alias = null)
```

Creates a condition with optional table-alias qualification.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$condition` | `array<array-key, mixed>` | Condition in Yii array format, kept unqualified for [`withAlias()`](/docs/extensions/soft-delete/reference/condition/index.md#method-withAlias). The rows of an `in` column tuple given as a [`Traversable`](https://www.php.net/manual/en/class.traversable.php) are read each time the condition is qualified, so pass an array or a rewindable iterator: a generator cannot be read again by a later [`withAlias()`](/docs/extensions/soft-delete/reference/condition/index.md#method-withAlias). |
| `$alias` | `string\|null` | Table alias that qualifies bare column names, or `null` to keep them unqualified. |

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

```php
public static function map(array<array-key, mixed> $condition, Closure(self): ?self $map): array<array-key, mixed>|null
```

Applies the callback to every soft-delete scope inside an `and` condition, recursing into nested `and` operands.

A scope the callback maps to `null` is removed, together with any nested `and` left without operands. Other
operands, and conditions that do not start with `and`, are returned unchanged.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$condition` | `array<array-key, mixed>` | Query condition in Yii array format. |
| `$map` | [`Closure`](https://www.php.net/manual/en/class.closure.php)`(self): ?self` | Callback that returns the replacement scope, or `null` to remove it. |

**Returns**

`array<array-key, mixed>|null`: The mapped condition, or `null` when no operand remains.

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

```php
public function withAlias(string $alias): self
```

Returns a new scope with the original condition qualified with the given table alias.

**Parameters**

| Parameter | Type | Description |
| --- | --- | --- |
| `$alias` | `string` |  |

**Returns**

`self`