diff --git a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php index 36d84d415..edb39afc6 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/AbstractEntityInheritancePersister.php @@ -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; } diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index b1bd56d8c..019d987d5 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -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 + ) + ); } } } diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index d0148f9cf..574cb371e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -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 + ) + ); } } } diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php new file mode 100644 index 000000000..5677075dd --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php @@ -0,0 +1,92 @@ + + */ +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 +{ +}