Permalink
Browse files

Add array parameter support in Query\Builder::exclude()

  • Loading branch information...
1 parent c8fc2e5 commit 412f9e0e66df3ecfa6ac5ded84a12d89126bdcab @pierrre pierrre committed Mar 29, 2013
Showing with 27 additions and 2 deletions.
  1. +6 −2 lib/Doctrine/MongoDB/Query/Builder.php
  2. +21 −0 tests/Doctrine/MongoDB/Tests/Query/BuilderTest.php
@@ -336,12 +336,16 @@ public function select($fieldName = null)
/**
* The fields not to select.
*
- * @param string $fieldName
+ * @param string|array $fieldName
* @return Builder
*/
public function exclude($fieldName = null)
{
- $select = func_get_args();
+ if (is_array($fieldName)) {
+ $select = $fieldName;
+ } else {
+ $select = func_get_args();
+ }
foreach ($select as $fieldName) {
$this->query['select'][$fieldName] = 0;
}
@@ -559,6 +559,27 @@ public function testExclude()
$this->assertEquals($expected, $qb->debug('select'));
}
+ public function testExcludeWithArray()
+ {
+ $qb = $this->getTestQueryBuilder()
+ ->exclude(array('foo', 'bar'));
+
+ $expected = array(
+ 'foo' => 0,
+ 'bar' => 0
+ );
+ $this->assertEquals($expected, $qb->debug('select'));
+ }
+
+ public function testExcludeWithNothing()
+ {
+ $qb = $this->getTestQueryBuilder()
+ ->exclude();
+
+ $expected = array();
+ $this->assertEquals($expected, $qb->debug('select'));
+ }
+
private function getTestQueryBuilder()
{
return $this->conn->selectCollection('db', 'users')->createQueryBuilder();

0 comments on commit 412f9e0

Please sign in to comment.