DDC-822 - Fix making queries with detached entities
This commit is contained in:
parent
de236e0456
commit
638c3df3a6
@ -242,10 +242,14 @@ final class Query extends AbstractQuery
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
|
if (is_object($value) && $this->_em->getMetadataFactory()->hasMetadataFor(get_class($value))) {
|
||||||
//TODO: Check that $value is MANAGED?
|
if ($this->_em->getUnitOfWork()->getEntityState($value) == UnitOfWork::STATE_MANAGED) {
|
||||||
$values = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
|
$idValues = $this->_em->getUnitOfWork()->getEntityIdentifier($value);
|
||||||
|
} else {
|
||||||
|
$class = $this->_em->getClassMetadata(get_class($value));
|
||||||
|
$idValuess = $class->getIdentifierValues($value);
|
||||||
|
}
|
||||||
$sqlPositions = $paramMappings[$key];
|
$sqlPositions = $paramMappings[$key];
|
||||||
$sqlParams += array_combine((array)$sqlPositions, $values);
|
$sqlParams += array_combine((array)$sqlPositions, $idValues);
|
||||||
} else {
|
} else {
|
||||||
foreach ($paramMappings[$key] as $position) {
|
foreach ($paramMappings[$key] as $position) {
|
||||||
$sqlParams[$position] = $value;
|
$sqlParams[$position] = $value;
|
||||||
|
@ -105,8 +105,8 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
} catch (\Exception $expected) {}
|
} catch (\Exception $expected) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testUninitializedLazyAssociationsAreIgnoredOnMerge() {
|
public function testUninitializedLazyAssociationsAreIgnoredOnMerge()
|
||||||
//$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
{
|
||||||
$user = new CmsUser;
|
$user = new CmsUser;
|
||||||
$user->name = 'Guilherme';
|
$user->name = 'Guilherme';
|
||||||
$user->username = 'gblanco';
|
$user->username = 'gblanco';
|
||||||
@ -136,5 +136,30 @@ class DetachedEntityTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertFalse($managedAddress2->user === $detachedAddress2->user);
|
$this->assertFalse($managedAddress2->user === $detachedAddress2->user);
|
||||||
$this->assertFalse($managedAddress2->user->__isInitialized__);
|
$this->assertFalse($managedAddress2->user->__isInitialized__);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-822
|
||||||
|
*/
|
||||||
|
public function testUseDetachedEntityAsQueryParameter()
|
||||||
|
{
|
||||||
|
$user = new CmsUser;
|
||||||
|
$user->name = 'Guilherme';
|
||||||
|
$user->username = 'gblanco';
|
||||||
|
$user->status = 'developer';
|
||||||
|
|
||||||
|
$this->_em->persist($user);
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->detach($user);
|
||||||
|
|
||||||
|
$dql = "SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.id = ?1";
|
||||||
|
$query = $this->_em->createQuery($dql);
|
||||||
|
$query->setParameter(1, $user);
|
||||||
|
|
||||||
|
$newUser = $query->getSingleResult();
|
||||||
|
|
||||||
|
$this->assertType('Doctrine\Tests\Models\CMS\CmsUser', $newUser);
|
||||||
|
$this->assertEquals('gblanco', $newUser->username);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user