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

Doctrine 2 Doctrine\ORM\Persisters\Entity\BasicEntityPersister::getSelectSQL() method issue #6538

Open
kbora504 opened this issue Jul 1, 2017 · 5 comments
Assignees

Comments

@kbora504
Copy link

kbora504 commented Jul 1, 2017

There seems to be a bug in method
public function getSelectSQL($criteria, $assoc = null, $lockMode = null, $limit = null, $offset = null, array $orderBy = null)
As per documentation of Doctrine\ORM\Persisters\Entity\EntityPersister the $criteria parameter should be of type array; so, the below code

$conditionSql = ($criteria instanceof Criteria)
            ? $this->getSelectConditionCriteriaSQL($criteria)
            : $this->getSelectConditionSQL($criteria, $assoc);

will never execute $this->getSelectConditionCriteriaSQL($criteria) statement, because it is always of type array. Please fix this, so that it accepts single criteria object too.

++ Exception

#0 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(1704): Doctrine\ORM\ORMException::unrecognizedField(0)
#1 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(1582): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementColumnSQL(0, NULL)
#2 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(1724): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionStatementSQL(0, Object(Doctrine\Common\Collections\Criteria), NULL)
#3 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(1058): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectConditionSQL(Array, NULL)
#4 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\Persisters\Entity\BasicEntityPersister.php(882): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->getSelectSQL(Array, NULL, NULL, 20, 0, NULL)
#5 C:\projects\data\vendor\doctrine\orm\lib\Doctrine\ORM\EntityRepository.php(181): Doctrine\ORM\Persisters\Entity\BasicEntityPersister->loadAll(Array, NULL, 20, 0)
#6 C:\projects\data\module\MyModule\src\DAO\DataDao.php(231): Doctrine\ORM\EntityRepository->findBy(Array, NULL, 20, 0)
#7 C:\projects\data\module\MyModule\src\Service\DataService.php(47): MyModule\DAO\DataDao->findData(Object(MyModule\Form\Data\PaginationOptions))
#8 C:\projects\data\module\MyModule\src\Controller\DataController.php(54): MyModule\Service\DataService->findData(Object(MyModule\Form\Data\PaginationOptions))
#9 C:\projects\data\vendor\zendframework\zend-mvc\src\Controller\AbstractActionController.php(78): MyModule\Controller\DataController->dataAction()
#10 C:\projects\data\vendor\zendframework\zend-eventmanager\src\EventManager.php(322): Zend\Mvc\Controller\AbstractActionController->onDispatch(Object(Zend\Mvc\MvcEvent))
#11 C:\projects\data\vendor\zendframework\zend-eventmanager\src\EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#12 C:\projects\data\vendor\zendframework\zend-mvc\src\Controller\AbstractController.php(106): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#13 C:\projects\data\vendor\zendframework\zend-mvc\src\DispatchListener.php(138): Zend\Mvc\Controller\AbstractController->dispatch(Object(Zend\Http\PhpEnvironment\Request), Object(Zend\Http\PhpEnvironment\Response))
#14 C:\projects\data\vendor\zendframework\zend-eventmanager\src\EventManager.php(322): Zend\Mvc\DispatchListener->onDispatch(Object(Zend\Mvc\MvcEvent))
#15 C:\projects\data\vendor\zendframework\zend-eventmanager\src\EventManager.php(179): Zend\EventManager\EventManager->triggerListeners(Object(Zend\Mvc\MvcEvent), Object(Closure))
#16 C:\projects\data\vendor\zendframework\zend-mvc\src\Application.php(332): Zend\EventManager\EventManager->triggerEventUntil(Object(Closure), Object(Zend\Mvc\MvcEvent))
#17 C:\projects\data\public\index.php(40): Zend\Mvc\Application->run()
#18 {main}
@Ocramius
Copy link
Member

Ocramius commented Jul 1, 2017

@kbora504 could you please write a failing test case that demonstrates the issue?

@kbora504
Copy link
Author

kbora504 commented Jul 2, 2017

It is very obvious from code written. Just check the passed parameter type is array and we are checking for instanceof Criteria.

@Ocramius
Copy link
Member

Ocramius commented Jul 2, 2017

It doesn't really matter from our perspective: tests verify the behavior and prevent regressions. No tests = no fix/merge ;-)

@kbora504
Copy link
Author

kbora504 commented Jul 2, 2017

@Ocramius I understand your point. But how can I write test case for a satement inside function?
:(

@Ocramius
Copy link
Member

Ocramius commented Jul 2, 2017

@kbora504 you got a stack trace there: how did you get to that failure? Can you isolate it and make an example that reproduces the problem? See https://github.com/doctrine/doctrine2/tree/388afb46d0cb3ed0c51332e8df0de9e942c2690b/tests/Doctrine/Tests/ORM/Functional/Ticket for examples

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

No branches or pull requests

2 participants