Permalink
Browse files

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.
  • Loading branch information...
1 parent 4b2a1d4 commit faf73426076e5980b86b914e8b768106e1c3465c @jmikola jmikola committed Feb 24, 2014
Showing with 6 additions and 6 deletions.
  1. +6 −6 lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php
@@ -77,9 +77,9 @@ protected function configure()
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
{
$dm = $this->getHelper('documentManager')->getDocumentManager();
- $query = json_decode($input->getArgument('query'));
- $cursor = $dm->getRepository($input->getArgument('class'))->findBy((array) $query);
- $cursor->hydrate((bool) $input->getOption('hydrate'));
+ $qb = $dm->getRepository($input->getArgument('class'))->createQueryBuilder();
+ $qb->setQueryArray((array) json_decode($input->getArgument('query')));
+ $qb->hydrate((bool) $input->getOption('hydrate'));
$depth = $input->getOption('depth');
@@ -92,18 +92,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
throw new \LogicException("Option 'skip' must contain an integer value");
}
- $cursor->skip((int) $skip);
+ $qb->skip((int) $skip);
}
if (($limit = $input->getOption('limit')) !== null) {
if ( ! is_numeric($limit)) {
throw new \LogicException("Option 'limit' must contain an integer value");
}
- $cursor->limit((int) $limit);
+ $qb->limit((int) $limit);
}
- $resultSet = $cursor->toArray();
+ $resultSet = $qb->getQuery->toArray();
\Doctrine\Common\Util\Debug::dump($resultSet, $depth);
}

0 comments on commit faf7342

Please sign in to comment.