mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
DDC-3175: Update documentation for QueryBuilder to give example of using "set()" with parameter #3935
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Jun 17, 2014).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user max.summe:
QueryBuilder->set method uses Expr\Comparison object, which tries to cast values as strings.
When trying to set('updated', new \DateTime) in an update statement, this causes an exception as \DateTime has no **toString method.
Not sure what the fix is - the format for the \DateTime there depends on the platform and ( I think) the type of field.
@doctrinebot commented on GitHub (Jun 17, 2014):
Comment created by stof:
you should not set a value directly in the DQL query. You should use the query parameters instead.
@doctrinebot commented on GitHub (Jun 17, 2014):
Comment created by max.summe:
So you're saying it should not be used like this.
$qb = $em->createQueryBuilder();
$qb->update('User', 'u')
->set("u.field", "new value")
->where("u.field = :oldvalue")
->setParameter("oldvalue", "old value");
Instead, it should be:
$qb = $em->createQueryBuilder();
$qb->update('User', 'u')
->set("u.field", ":value")
->where("u.field = :oldvalue")
->setParameter("oldvalue", "old value")
->setParameter("value", "new value");
Is that correct?
If yes, it would be helpful to add an example to the documentation in this page: http://docs.doctrine-project.org/en/latest/reference/query-builder.html