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

Deprecate omitting the alias in QueryBuilder::update() and delete() #9765

Closed
wants to merge 13 commits into from
24 changes: 24 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,29 @@
# Upgrade to 2.13

## Deprecated omitting alias argument for `QueryBuilder::update` and `QueryBuilder::delete`
Hanmac marked this conversation as resolved.
Show resolved Hide resolved

When making an Update or Delete Query and when passing a class/type to the function, the alias argument should not be omitted.
Hanmac marked this conversation as resolved.
Show resolved Hide resolved

### Before

```php
$qb = $em->createQueryBuilder()
->delete('User u')
->where('u.id = :user_id')
->setParameter('user_id', 1);
```

### After

For backward-compatibility reasons, the parameter has to be optional and to make it possible to call `update()` and `delete()` without class/type argument.

Hanmac marked this conversation as resolved.
Show resolved Hide resolved
```php
$qb = $em->createQueryBuilder()
->delete('User', 'u')
->where('u.id = :user_id')
->setParameter('user_id', 1);
```

## Deprecated omitting second argument to `NamingStrategy::joinColumnName`

When implementing `NamingStrategy`, it is deprecated to implement
Expand Down
17 changes: 17 additions & 0 deletions lib/Doctrine/ORM/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Deprecations\Deprecation;
use Doctrine\ORM\Query\Expr;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Query\QueryExpressionVisitor;
Expand Down Expand Up @@ -844,6 +845,14 @@ public function delete($delete = null, $alias = null)
return $this;
}

if (! $alias) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9733',
'Omitting the alias is deprecated and will throw an exception in Doctrine 3.0.'
);
}

return $this->add('from', new Expr\From($delete, $alias));
}

Expand Down Expand Up @@ -871,6 +880,14 @@ public function update($update = null, $alias = null)
return $this;
}

if (! $alias) {
Deprecation::trigger(
'doctrine/orm',
'https://github.com/doctrine/orm/issues/9733',
'Omitting the alias is deprecated and will throw an exception in Doctrine 3.0.'
);
}

return $this->add('from', new Expr\From($update, $alias));
}

Expand Down