Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow ExpressionInterface for $alias parameter of QueryPartsInterface::withQuery() #842

Merged
merged 2 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
- Chg #838: Remove `SchemaInterface::TYPE_JSONB` constant (@Tigrov)
- Chg #839: Remove `TableSchemaInterface::compositeForeignKey()` method (@Tigrov)
- Chg #840: Remove parameter `$withColumn` from `QuoterInterface::getTableNameParts()` method (@Tigrov)
- Chg #840: Remove `Quoter::unquoteParts()` method (@Tigrov)
- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method
- Enh #840: Remove `Quoter::unquoteParts()` method (@Tigrov)
- Chg #841: Remove `$rawSql` parameter from `AbstractCommand::internalExecute()` method
and `AbstractPdoCommand::internalExecute()` method (@Tigrov)
- Enh #842: Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method (@Tigrov)

## 1.3.0 March 21, 2024

Expand Down
4 changes: 4 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,7 @@ $db->createCommand()->insertBatch('user', $values)->execute();
### Remove deprecated constants

- `SchemaInterface::TYPE_JSONB`

### Other changes

- Allow `ExpressionInterface` for `$alias` parameter of `QueryPartsInterface::withQuery()` method
7 changes: 5 additions & 2 deletions src/Query/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -669,8 +669,11 @@ public function where(array|string|ExpressionInterface|null $condition, array $p
return $this;
}

public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static
{
public function withQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false
): static {
$this->withQueries[] = ['query' => $query, 'alias' => $alias, 'recursive' => $recursive];
return $this;
}
Expand Down
9 changes: 7 additions & 2 deletions src/Query/QueryPartsInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -680,10 +680,15 @@ public function where(array|string|ExpressionInterface|null $condition, array $p
* Prepends an SQL statement using `WITH` syntax.
*
* @param QueryInterface|string $query The SQL statement to append using `UNION`.
* @param string $alias The query alias in `WITH` construction.
* @param ExpressionInterface|string $alias The query alias in `WITH` construction.
* To specify the alias in plain SQL, you may pass an instance of {@see ExpressionInterface}.
* @param bool $recursive Its `true` if using `WITH RECURSIVE` and `false` if using `WITH`.
*/
public function withQuery(QueryInterface|string $query, string $alias, bool $recursive = false): static;
public function withQuery(
QueryInterface|string $query,
ExpressionInterface|string $alias,
bool $recursive = false
): static;

/**
* Specifies the `WITH` query clause for the query.
Expand Down
1 change: 1 addition & 0 deletions tests/Provider/QueryBuilderProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -1527,6 +1527,7 @@ public static function cteAliases(): array
'with one column' => ['a(b)', '[[a]]([[b]])'],
'with columns' => ['a(b,c,d)', '[[a]]([[b]], [[c]], [[d]])'],
'with extra space' => ['a(b,c,d) ', 'a(b,c,d) '],
'expression' => [new Expression('a(b,c,d)'), 'a(b,c,d)'],
];
}

Expand Down
Loading