rector-doctrine icon indicating copy to clipboard operation
rector-doctrine copied to clipboard

Orm querybuilder set parameters to collection

Open marcelthole opened this issue 1 year ago • 2 comments

hey,

i have a new feature proposal for changing the method signature for Doctrine\ORM\QueryBuilder::setParameters from the array type from Doctrine ORM 2.x to the ArrayCollection with Parameter type of ORM 3.x

see https://github.com/doctrine/orm/pull/9490 see https://github.com/doctrine/orm/blob/3.0.x/UPGRADE.md#query-querybuilder-and-nativequery-parameters-bc-break

marcelthole avatar Jul 10 '24 12:07 marcelthole

Hi.

I was about to get cracking on this and saw your PR @marcelthole :+1:

It would be nice if you could transform the following:

$params = ['name' => 'John'];
if ($someCondition) {
    $qb->andWhere('age > :age');
    $params['age'] = 18;
}
$qb->setParameters($params);

into

$params = new ArrayCollection([new Parameter('name', 'John')]);
if ($someCondition) {
    $qb->andWhere('age > :age');
    $params->add(new Parameter('age', 18));
}
$qb->setParameters($params);

JoolsMcFly avatar Sep 18 '24 08:09 JoolsMcFly

@JoolsMcFly i like the idea and created a second PR for that here: https://github.com/rectorphp/rector-doctrine/pull/346 if this one gets merged we could check the addition :)

marcelthole avatar Sep 19 '24 15:09 marcelthole

I think this one is good to go. What do you think @samsonasik ?

TomasVotruba avatar Feb 28 '25 13:02 TomasVotruba

Thanks + thank you @marcelthole

TomasVotruba avatar Feb 28 '25 13:02 TomasVotruba