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

DDC-3175: Update documentation for QueryBuilder to give example of using "set()" with parameter #3956

Open
doctrinebot opened this issue Jun 17, 2014 · 2 comments
Assignees

Comments

@doctrinebot
Copy link

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
Copy link
Author

Comment created by stof:

you should not set a value directly in the DQL query. You should use the query parameters instead.

@doctrinebot
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants