diff --git a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php index 3720e47b090..4b5c0892134 100644 --- a/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php +++ b/lib/Doctrine/ORM/Persisters/Collection/ManyToManyPersister.php @@ -238,6 +238,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $targetClass = $this->em->getClassMetadata($mapping['targetEntity']); $onConditions = $this->getOnConditionSQL($mapping); $whereClauses = $params = []; + $paramTypes = []; if (! $mapping['isOwningSide']) { $associationSourceClass = $targetClass; @@ -253,6 +254,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $params[] = $ownerMetadata->containsForeignIdentifier ? $id[$ownerMetadata->getFieldForColumn($value)] : $id[$ownerMetadata->fieldNames[$value]]; + $paramTypes[] = PersisterHelper::getTypeOfColumn($value, $ownerMetadata, $this->em); } $parameters = $this->expandCriteriaParameters($criteria); @@ -263,6 +265,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $field = $this->quoteStrategy->getColumnName($name, $targetClass, $this->platform); $whereClauses[] = sprintf('te.%s %s ?', $field, $operator); $params[] = $value; + $paramTypes[] = PersisterHelper::getTypeOfColumn($field, $targetClass, $this->em); } $tableName = $this->quoteStrategy->getTableName($targetClass, $this->platform); @@ -281,7 +284,7 @@ public function loadCriteria(PersistentCollection $collection, Criteria $criteri $sql .= $this->getLimitSql($criteria); - $stmt = $this->conn->executeQuery($sql, $params); + $stmt = $this->conn->executeQuery($sql, $params, $paramTypes); return $this ->em diff --git a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php index 5e360d85db1..70e6267439a 100644 --- a/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionCriteriaTest.php @@ -11,6 +11,8 @@ use Doctrine\Tests\Models\Tweet\Tweet; use Doctrine\Tests\Models\Tweet\User; use Doctrine\Tests\Models\Tweet\User as TweetUser; +use Doctrine\Tests\Models\ValueConversionType\InversedManyToManyExtraLazyEntity; +use Doctrine\Tests\Models\ValueConversionType\OwningManyToManyExtraLazyEntity; use Doctrine\Tests\OrmFunctionalTestCase; class PersistentCollectionCriteriaTest extends OrmFunctionalTestCase @@ -19,6 +21,7 @@ protected function setUp(): void { $this->useModelSet('tweet'); $this->useModelSet('quote'); + $this->useModelSet('vct_manytomany_extralazy'); parent::setUp(); } @@ -95,4 +98,31 @@ public function testCanCountWithoutLoadingPersistentCollection(): void $this->assertCount(1, $tweets); $this->assertFalse($tweets->isInitialized()); } + + public function testCanHandleComplexTypesOnAssociation(): void + { + $parent = new OwningManyToManyExtraLazyEntity(); + $parent->id2 = 'Alice'; + + $this->_em->persist($parent); + + $child = new InversedManyToManyExtraLazyEntity(); + $child->id1 = 'Bob'; + + $this->_em->persist($child); + + $parent->associatedEntities->add($child); + + $this->_em->flush(); + $this->_em->clear(); + + $parent = $this->_em->find(OwningManyToManyExtraLazyEntity::class, $parent->id2); + + $criteria = Criteria::create()->where(Criteria::expr()->eq('id1', 'Bob')); + + $result = $parent->associatedEntities->matching($criteria); + + $this->assertCount(1, $result); + $this->assertEquals('Bob', $result[0]->id1); + } }