Skip to content

Commit

Permalink
Merge branch 'gh621' into 1.0.x
Browse files Browse the repository at this point in the history
* gh621:
  Fix querying for empty simple ref many

Closes #1313.
  • Loading branch information
alcaeus committed Dec 17, 2015
2 parents 1a2c2ef + 244ff35 commit 8876b91
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ODM/MongoDB/Persisters/DocumentPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,7 @@ private function prepareQueryElement($fieldName, $value = null, $class = null, $
}

// No further preparation unless we're dealing with a simple reference
if (empty($mapping['reference']) || empty($mapping['simple'])) {
if (empty($mapping['reference']) || empty($mapping['simple']) || empty((array) $value)) {
return array($fieldName, $value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,15 @@ public function testQueryForNonIds() {
$qb->field('user')->exists(true);
$this->assertEquals(array('userId' => array('$exists' => true)), $qb->getQueryArray());
}

public function testRemoveDocumentByEmptyRefMany()
{
$qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser');
$qb->field('users')->equals(array());
$this->assertEquals(array('users' => array()), $qb->getQueryArray());

$qb = $this->dm->createQueryBuilder('Documents\SimpleReferenceUser');
$qb->field('users')->equals(new \stdClass());
$this->assertEquals(array('users' => new \stdClass()), $qb->getQueryArray());
}
}

0 comments on commit 8876b91

Please sign in to comment.