DDC-2140: [GH-512] Added addParameters() to Query and QueryBuilder #2694

Closed
opened 2026-01-22 14:00:48 +01:00 by admin · 5 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 13, 2012).

Originally assigned to: @lcobucci on GitHub.

Jira issue originally created by user @beberlei:

This issue is created automatically through a Github pull request on behalf of jappie:

Url: https://github.com/doctrine/doctrine2/pull/512

Message:

This method behaves like setParameters() before version 2.3:
It will add new parameters to the collection, and override any existing positions/names.

It can take a Doctrine\Common\Collections\ArrayCollection with Doctrine\ORM\Query\Parameter objects, as well as a plain array with key/value pairs, as argument.

This will greatly ease the upgrade to Doctrine 2.3, because you only need to perform a project-wide replace of setParameters with addParameters, in stead of going into your code and determine if calls to setParameters are ok or need refactoring.

I've also added unit-tests to maintain integrity.

Originally created by @doctrinebot on GitHub (Nov 13, 2012). Originally assigned to: @lcobucci on GitHub. Jira issue originally created by user @beberlei: This issue is created automatically through a Github pull request on behalf of jappie: Url: https://github.com/doctrine/doctrine2/pull/512 Message: This method behaves like `setParameters()` before version 2.3: It will add new parameters to the collection, and override any existing positions/names. It can take a `Doctrine\Common\Collections\ArrayCollection` with `Doctrine\ORM\Query\Parameter` objects, as well as a plain `array` with key/value pairs, as argument. This will greatly ease the upgrade to Doctrine 2.3, because you only need to perform a project-wide replace of `setParameters` with `addParameters`, in stead of going into your code and determine if calls to `setParameters` are ok or need refactoring. I've also added unit-tests to maintain integrity.
admin added the ImprovementDuplicate labels 2026-01-22 14:00:48 +01:00
admin closed this issue 2026-01-22 14:00:49 +01:00
Author
Owner

@doctrinebot commented on GitHub (Nov 20, 2012):

Comment created by @beberlei:

A related Github Pull-Request [GH-512] was closed
https://github.com/doctrine/doctrine2/pull/512

@doctrinebot commented on GitHub (Nov 20, 2012): Comment created by @beberlei: A related Github Pull-Request [GH-512] was closed https://github.com/doctrine/doctrine2/pull/512
Author
Owner

@doctrinebot commented on GitHub (Nov 20, 2012):

Comment created by jasper@nerdsweide.nl:

{quote}
I don't feel strong need to have such an API.
If you want to keep track and merge collection of parameters, all you have to do is create an array (or an ArrayCollection), manipulate the instance and then setParameters at the end.
Unless you give me a stronger argument, this code won't be in. Closing for now.
{quote}

Hi Guilherme,

I agree that such a method makes less sense in Query, because when you write a DQL string all parameters are known at once. But when using the QueryBuilder you might need different parameters in different cases, so addParameters() becomes useful there.

I guess it's just a convenience method, like IMHO setParameter() is. (You could just do $qb->getParameters()->add())

The main reason for adding the method was, like I said, upgrading to Doctrine 2.3. I've already upgraded all my projects to Doctrine 2.3, so the method is less useful for me now. But it took me a full day to refactor my repositories, because there is no safe way to automate the process. A simple search-and-replace setParameters() to addParameters() would have taken me 5 minutes ;)

I'm content with your decision.
If others find addParameters() useful, I hope they let us know.

@doctrinebot commented on GitHub (Nov 20, 2012): Comment created by jasper@nerdsweide.nl: {quote} I don't feel strong need to have such an API. If you want to keep track and merge collection of parameters, all you have to do is create an array (or an ArrayCollection), manipulate the instance and then setParameters at the end. Unless you give me a stronger argument, this code won't be in. Closing for now. {quote} Hi Guilherme, I agree that such a method makes less sense in `Query`, because when you write a DQL string all parameters are known at once. But when using the `QueryBuilder` you might need different parameters in different cases, so `addParameters()` becomes useful there. I guess it's just a convenience method, like IMHO `setParameter()` is. (You could just do `$qb->getParameters()->add()`) The main reason for adding the method was, like I said, upgrading to Doctrine 2.3. I've already upgraded all my projects to Doctrine 2.3, so the method is less useful for me now. But it took me a full day to refactor my repositories, because there is no safe way to automate the process. A simple search-and-replace `setParameters()` to `addParameters()` would have taken me 5 minutes ;) I'm content with your decision. If others find `addParameters()` useful, I hope they let us know.
Author
Owner

@doctrinebot commented on GitHub (Feb 8, 2014):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-512] was closed:
https://github.com/doctrine/dbal/pull/512

@doctrinebot commented on GitHub (Feb 8, 2014): Comment created by @doctrinebot: A related Github Pull-Request [GH-512] was closed: https://github.com/doctrine/dbal/pull/512
Author
Owner

@malukenho commented on GitHub (Jan 11, 2017):

@Ocramius @lcobucci can be closed?

@malukenho commented on GitHub (Jan 11, 2017): @Ocramius @lcobucci can be closed?
Author
Owner

@lcobucci commented on GitHub (Jan 12, 2017):

Looks like it was fixed by b3e7493278 and 6521e51170 (ages ago)...

Thanks @malukenho 😉

@lcobucci commented on GitHub (Jan 12, 2017): Looks like it was fixed by b3e7493278ce4915d7b741a4ea3cd390030b82bb and 6521e511706baa897f4500b05cb835d749d65692 (ages ago)... Thanks @malukenho 😉
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2694