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

fix for incorrect query building in Repositories. #691

Merged
merged 1 commit into from
Dec 6, 2013

Conversation

molchanoviv
Copy link

fix for incorrect query building in Repositories If $value is array.

$queryBuilder->andWhere($this->getPropertyName($property) . ' = :' . $property);
} else {
$queryBuilder->andWhere($this->getPropertyName($property) . ' IN (:' . $property . ')');
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would replace it with Doctrine Expr class calls:

if (!is_array($value)) {
    $queryBuilder->andWhere($queryBuilder->expr()->eq($this->getPropertyName($property), $property));
} else {
    $queryBuilder->andWhere($queryBuilder->expr()->in($this->getPropertyName($property), array($property)));
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great idea. I forgot about Expr. Thanks

@molchanoviv
Copy link
Author

@Arn0d I agree. What about adding constants with operators from the WHERE clause to Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository and use this constants as unnecessary paramter in findBy and findOneBy functions?

ping @pjedrzejewski @stloyd

@molchanoviv
Copy link
Author

@Arn0d When I started to implement this i realized that the idea with constants is not the best. Because in the case when $value is array we can want to create complicated query like ... WHERE table.field1 <> :param1 AND (table.field2 = :param2 OR table.field2 = :param3) ... Thats why i think creating this queries manually by query builder or writing your own DQL query still is the best solution.

@molchanoviv
Copy link
Author

@pjedrzejewski Please merge. We are going to QA tonight. Thats why i need this fixed.

@stloyd
Copy link
Contributor

stloyd commented Dec 6, 2013

@molchanoviv This can't be merge till Travis-CI will pass, now it dies with Doctrine exception, please fix it and then we can merge.

@arnolanglade
Copy link
Contributor

@molchanoviv : ok !

if (!is_array($value)) {
$queryBuilder->andWhere($queryBuilder->expr()->eq($this->getPropertyName($property), ':' . $property));
} else {
$queryBuilder->andWhere($queryBuilder->expr()->in($this->getPropertyName($property), ':' . $property));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, it must be array(':'.$property) otherwise Doctrine will fail.

pjedrzejewski pushed a commit that referenced this pull request Dec 6, 2013
fix for incorrect query building in Repositories.
@pjedrzejewski pjedrzejewski merged commit 9953b57 into Sylius:master Dec 6, 2013
@pjedrzejewski
Copy link
Member

Thanks Ivan!

@stloyd
Copy link
Contributor

stloyd commented Dec 6, 2013

This broke the spec: spec\Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepositorySpec.

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

Successfully merging this pull request may close these issues.

None yet

4 participants