Skip to content

Loading…

QueryCommand not working #801

Closed
emri99 opened this Issue · 1 comment

2 participants

@emri99

Unable to launch the QueryCommand; I get this error:

bin/console odm:query User {} 

PHP Fatal error:  Call to a member function hydrate() on a non-object in /blabla/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php on line 83
PHP Stack trace:
PHP   1. {main}() /blabla/bin/console:0
PHP   2. Symfony\Component\Console\Application->run() /blabla/bin/console:33
PHP   3. Symfony\Component\Console\Application->doRun() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:121
PHP   4. Symfony\Component\Console\Application->doRunCommand() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:191
PHP   5. Symfony\Component\Console\Command\Command->run() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:881
PHP   6. Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand->execute() /blabla/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241

Fatal error: Call to a member function hydrate() on a non-object in /blabla/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php on line 83

Call Stack:
    0.0055     645624   1. {main}() /blabla/bin/console:0
    0.0370    5877248   2. Symfony\Component\Console\Application->run() /blabla/bin/console:33
    0.0419    6464952   3. Symfony\Component\Console\Application->doRun() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:121
    0.0423    6464952   4. Symfony\Component\Console\Application->doRunCommand() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:191
    0.0424    6465120   5. Symfony\Component\Console\Command\Command->run() /blabla/vendor/symfony/console/Symfony/Component/Console/Application.php:881
    0.0433    6466096   6. Doctrine\ODM\MongoDB\Tools\Console\Command\QueryCommand->execute() /blabla/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:241

Possible fix:

replace line 81

$cursor = $dm->getRepository($input->getArgument('class'))->findBy((array) $query);

with

$cursor = $dm->getRepository($input->getArgument('class'))->createQueryBuilder()->setQueryArray((array) $query)->getQuery()->execute();
@jmikola jmikola added a commit that closed this issue
@jmikola jmikola Construct query builder in QueryCommand (fixes #801)
Since #752, the repository find methods return arrays instead of cursors in order to be consistent with the common repository interface. With this change, a query builder is used, and the skip/limit/hydrate options can be applied to the builder directly.
faf7342
@jmikola jmikola closed this in faf7342
@jmikola
Doctrine member

@emri99: Thanks for reporting this. Please let me know if the referenced PR fixed your issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.