commit
6164f17229
@ -80,13 +80,15 @@ abstract class AbstractEntityInheritancePersister extends BasicEntityPersister
|
||||
* @param string $tableAlias
|
||||
* @param string $joinColumnName
|
||||
* @param string $className
|
||||
* @param string $type
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className)
|
||||
protected function getSelectJoinColumnSQL($tableAlias, $joinColumnName, $className, $type)
|
||||
{
|
||||
$columnAlias = $this->getSQLColumnAlias($joinColumnName);
|
||||
$this->rsm->addMetaResult('r', $columnAlias, $joinColumnName);
|
||||
|
||||
$this->rsm->addMetaResult('r', $columnAlias, $joinColumnName, false, $type);
|
||||
|
||||
return $tableAlias . '.' . $joinColumnName . ' AS ' . $columnAlias;
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ use Doctrine\DBAL\LockMode;
|
||||
use Doctrine\DBAL\Types\Type;
|
||||
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Utility\PersisterHelper;
|
||||
|
||||
/**
|
||||
* The joined subclass persister maps a single entity instance to several tables in the
|
||||
@ -457,7 +458,18 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
? $mapping['inherited']
|
||||
: $this->class->name;
|
||||
|
||||
$columnList[] = $this->getSelectJoinColumnSQL($tableAlias, $srcColumn, $className);
|
||||
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||
|
||||
$columnList[] = $this->getSelectJoinColumnSQL(
|
||||
$tableAlias,
|
||||
$srcColumn,
|
||||
$className,
|
||||
PersisterHelper::getTypeOfColumn(
|
||||
$mapping['sourceToTargetKeyColumns'][$srcColumn],
|
||||
$targetClass,
|
||||
$this->em
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@ -495,7 +507,18 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
||||
? $mapping['inherited']
|
||||
: $subClass->name;
|
||||
|
||||
$columnList[] = $this->getSelectJoinColumnSQL($tableAlias, $srcColumn, $className);
|
||||
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||
|
||||
$columnList[] = $this->getSelectJoinColumnSQL(
|
||||
$tableAlias,
|
||||
$srcColumn,
|
||||
$className,
|
||||
PersisterHelper::getTypeOfColumn(
|
||||
$mapping['sourceToTargetKeyColumns'][$srcColumn],
|
||||
$targetClass,
|
||||
$this->em
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace Doctrine\ORM\Persisters\Entity;
|
||||
|
||||
use Doctrine\ORM\Mapping\ClassMetadata;
|
||||
use Doctrine\Common\Collections\Criteria;
|
||||
use Doctrine\ORM\Utility\PersisterHelper;
|
||||
|
||||
/**
|
||||
* Persister for entities that participate in a hierarchy mapped with the
|
||||
@ -88,7 +89,19 @@ class SingleTablePersister extends AbstractEntityInheritancePersister
|
||||
|
||||
foreach ($assoc['targetToSourceKeyColumns'] as $srcColumn) {
|
||||
$className = isset($assoc['inherited']) ? $assoc['inherited'] : $this->class->name;
|
||||
$columnList[] = $this->getSelectJoinColumnSQL($tableAlias, $srcColumn, $className);
|
||||
|
||||
$targetClass = $this->em->getClassMetadata($mapping['targetEntity']);
|
||||
|
||||
$columnList[] = $this->getSelectJoinColumnSQL(
|
||||
$tableAlias,
|
||||
$srcColumn,
|
||||
$className,
|
||||
PersisterHelper::getTypeOfColumn(
|
||||
$mapping['sourceToTargetKeyColumns'][$srcColumn],
|
||||
$targetClass,
|
||||
$this->em
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
92
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php
Normal file
92
tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php
Normal file
@ -0,0 +1,92 @@
|
||||
<?php
|
||||
|
||||
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
||||
|
||||
use Doctrine\Tests\OrmFunctionalTestCase;
|
||||
|
||||
/**
|
||||
* Functional tests for get Id after clone child entity
|
||||
*
|
||||
* @author Lallement Thomas <thomas.lallement@9online.fr>
|
||||
*/
|
||||
class DDC3223Test extends OrmFunctionalTestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->setUpEntitySchema(array(
|
||||
'Doctrine\Tests\ORM\Functional\Ticket\Journalist',
|
||||
'Doctrine\Tests\ORM\Functional\Ticket\Participant',
|
||||
'Doctrine\Tests\ORM\Functional\Ticket\Status',
|
||||
'Doctrine\Tests\ORM\Functional\Ticket\ProfileStatus',
|
||||
));
|
||||
}
|
||||
|
||||
public function testIssueGetId()
|
||||
{
|
||||
$profileStatus = new ProfileStatus();
|
||||
|
||||
$participant = new Journalist();
|
||||
$participant->profileStatus = $profileStatus;
|
||||
|
||||
$this->_em->persist($profileStatus);
|
||||
$this->_em->persist($participant);
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$participant = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\Participant', $participant->id);
|
||||
|
||||
$profileStatus = clone $participant->profileStatus;
|
||||
|
||||
$this->assertSame(1, $profileStatus->getId(), 'The identifier on the cloned instance is an integer');
|
||||
}
|
||||
}
|
||||
|
||||
/** @Entity @Table(name="ddc3223_journalist") */
|
||||
class Journalist extends Participant
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity @Table(name="ddc3223_participant")
|
||||
* @InheritanceType("JOINED")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({
|
||||
* "journalist" = "Journalist",
|
||||
* })
|
||||
*/
|
||||
class Participant
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue */
|
||||
public $id;
|
||||
|
||||
/** @ManyToOne(targetEntity="ProfileStatus") */
|
||||
public $profileStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity @Table(name="ddc3223_status")
|
||||
* @InheritanceType("SINGLE_TABLE")
|
||||
* @DiscriminatorColumn(name="discr", type="string")
|
||||
* @DiscriminatorMap({
|
||||
* "profile" = "ProfileStatus",
|
||||
* })
|
||||
*/
|
||||
class Status
|
||||
{
|
||||
/** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */
|
||||
private $id;
|
||||
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @Entity
|
||||
*/
|
||||
class ProfileStatus extends Status
|
||||
{
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user