Skip to content

Commit faf7342

Browse files
committed
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.
1 parent 4b2a1d4 commit faf7342

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

lib/Doctrine/ODM/MongoDB/Tools/Console/Command/QueryCommand.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ protected function configure()
7777
protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
7878
{
7979
$dm = $this->getHelper('documentManager')->getDocumentManager();
80-
$query = json_decode($input->getArgument('query'));
81-
$cursor = $dm->getRepository($input->getArgument('class'))->findBy((array) $query);
82-
$cursor->hydrate((bool) $input->getOption('hydrate'));
80+
$qb = $dm->getRepository($input->getArgument('class'))->createQueryBuilder();
81+
$qb->setQueryArray((array) json_decode($input->getArgument('query')));
82+
$qb->hydrate((bool) $input->getOption('hydrate'));
8383

8484
$depth = $input->getOption('depth');
8585

@@ -92,18 +92,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
9292
throw new \LogicException("Option 'skip' must contain an integer value");
9393
}
9494

95-
$cursor->skip((int) $skip);
95+
$qb->skip((int) $skip);
9696
}
9797

9898
if (($limit = $input->getOption('limit')) !== null) {
9999
if ( ! is_numeric($limit)) {
100100
throw new \LogicException("Option 'limit' must contain an integer value");
101101
}
102102

103-
$cursor->limit((int) $limit);
103+
$qb->limit((int) $limit);
104104
}
105105

106-
$resultSet = $cursor->toArray();
106+
$resultSet = $qb->getQuery->toArray();
107107

108108
\Doctrine\Common\Util\Debug::dump($resultSet, $depth);
109109
}

0 commit comments

Comments
 (0)