diff --git a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php index 74b86208b..b06358a20 100644 --- a/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php +++ b/lib/Doctrine/ORM/Persisters/SqlExpressionVisitor.php @@ -65,7 +65,10 @@ class SqlExpressionVisitor extends ExpressionVisitor $field = $comparison->getField(); $value = $comparison->getValue()->getValue(); // shortcut for walkValue() - if (isset($this->classMetadata->associationMappings[$field]) && ! is_object($value)) { + if (isset($this->classMetadata->associationMappings[$field]) && + ! is_object($value) && + ! in_array($comparison->getOperator(), array(Comparison::IN, Comparison::NIN))) { + throw PersisterException::matchingAssocationFieldRequiresObject($this->classMetadata->name, $field); } diff --git a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php index 48e5f3389..517ff3d97 100644 --- a/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/EntityRepositoryTest.php @@ -790,7 +790,30 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); $criteria = new Criteria( - Criteria::expr()->gte('user', $user) + Criteria::expr()->eq('user', $user) + ); + + $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress'); + $addresses = $repository->matching($criteria); + + $this->assertEquals(1, count($addresses)); + + $addresses = new ArrayCollection($repository->findAll()); + + $this->assertEquals(1, count($addresses->matching($criteria))); + } + + /** + * @group DDC-2430 + */ + public function testMatchingCriteriaAssocationInWithArray() + { + list($userId, $addressId) = $this->loadAssociatedFixture(); + + $user = $this->_em->find('Doctrine\Tests\Models\CMS\CmsUser', $userId); + + $criteria = new Criteria( + Criteria::expr()->in('user', array($user)) ); $repository = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsAddress');