1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Fix parameter value processing for objects with unloaded metadata

This commit is contained in:
Andreas Braun 2018-11-13 09:08:46 +01:00 committed by Luís Cobucci
parent 5208035003
commit 0552749059
No known key found for this signature in database
GPG Key ID: EC61C5F01750ED3C
2 changed files with 34 additions and 5 deletions

View File

@ -19,10 +19,12 @@
namespace Doctrine\ORM;
use Doctrine\Common\Persistence\Mapping\MappingException;
use Doctrine\Common\Util\ClassUtils;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping\MappingException as ORMMappingException;
use Doctrine\ORM\Query\Parameter;
use Doctrine\ORM\Cache\QueryCacheKey;
use Doctrine\DBAL\Cache\QueryCacheProfile;
@ -410,16 +412,24 @@ abstract class AbstractQuery
return $value;
}
if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(ClassUtils::getClass($value))) {
if ($value instanceof Mapping\ClassMetadata) {
return $value->name;
}
if (! is_object($value)) {
return $value;
}
try {
$value = $this->_em->getUnitOfWork()->getSingleIdentifierValue($value);
if ($value === null) {
throw ORMInvalidArgumentException::invalidIdentifierBindingEntity();
}
}
if ($value instanceof Mapping\ClassMetadata) {
return $value->name;
} catch (MappingException | ORMMappingException $e) {
// Silence any mapping exceptions. These can occur if the object in
// question is not a mapped entity, in which case we just don't do
// any preparation on the value.
}
return $value;

View File

@ -189,6 +189,25 @@ class QueryTest extends OrmTestCase
);
}
public function testProcessParameterValueObject() : void
{
$query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.user = :user');
$user = new CmsUser();
$user->id = 12345;
self::assertSame(
12345,
$query->processParameterValue($user)
);
}
public function testProcessParameterValueNull() : void
{
$query = $this->_em->createQuery('SELECT a FROM Doctrine\Tests\Models\CMS\CmsAddress a WHERE a.user = :user');
self::assertNull($query->processParameterValue(null));
}
public function testDefaultQueryHints()
{
$config = $this->_em->getConfiguration();