Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

[DDC-2478] Support null association comparison #694

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 13, 2013
  1. @FabioBatSilva

    Fix DDC-2478

    FabioBatSilva authored FabioBatSilva committed
This page is out of date. Refresh to see the latest.
View
1  lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php
@@ -66,6 +66,7 @@ public function walkComparison(Comparison $comparison)
$value = $comparison->getValue()->getValue(); // shortcut for walkValue()
if (isset($this->classMetadata->associationMappings[$field]) &&
+ $value !== null &&
! is_object($value) &&
! in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) {
View
29 tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php
@@ -843,6 +843,35 @@ public function testMatchingCriteriaContainsComparison()
}
/**
+ * @group DDC-2478
+ */
+ public function testMatchingCriteriaNullAssocComparison()
+ {
+ $fixtures = $this->loadFixtureUserEmail();
+ $user = $this->_em->merge($fixtures[0]);
+ $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
+ $criteriaIsNull = Criteria::create()->where(Criteria::expr()->isNull('email'));
+ $criteriaEqNull = Criteria::create()->where(Criteria::expr()->eq('email', null));
+
+ $user->setEmail(null);
+ $this->_em->persist($user);
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $usersIsNull = $repository->matching($criteriaIsNull);
+ $usersEqNull = $repository->matching($criteriaEqNull);
+
+ $this->assertCount(1, $usersIsNull);
+ $this->assertCount(1, $usersEqNull);
+
+ $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersIsNull[0]);
+ $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $usersEqNull[0]);
+
+ $this->assertNull($usersIsNull[0]->getEmail());
+ $this->assertNull($usersEqNull[0]->getEmail());
+ }
+
+ /**
* @group DDC-2055
*/
public function testCreateResultSetMappingBuilder()
Something went wrong with that request. Please try again.