From 556c562258d73c2f3d9fc9c209bbf9b70b227f1a Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 22 Jul 2014 09:15:11 +0200 Subject: [PATCH 1/6] Failing test (get id return string type) --- .../ORM/Functional/Ticket/DDC0003Test.php | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php new file mode 100644 index 000000000..e0468cea9 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php @@ -0,0 +1,104 @@ + + */ +class DDC0003Test 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->assertEquals('integer', gettype($profileStatus->getId())); + $this->assertEquals(1, $profileStatus->getId()); + } +} + +/** + * @Entity @Table(name="ddc0003_journalist") + */ +class Journalist extends Participant +{ +} + +/** + * @Entity @Table(name="ddc0003_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="ddc0003_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 +{ + +} From 033b8e51e95fcda698cd09888e086c25c43a72ca Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 22 Jul 2014 15:20:44 +0200 Subject: [PATCH 2/6] Create DDC3223Test.php --- .../ORM/Functional/Ticket/DDC3223Test.php | 103 ++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php 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..f3d65f864 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php @@ -0,0 +1,103 @@ + + */ +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 +{ + +} From a0165858c4f2902f7b1d187aaf3456f48392a87b Mon Sep 17 00:00:00 2001 From: Thomas Lallement Date: Tue, 22 Jul 2014 15:21:34 +0200 Subject: [PATCH 3/6] Delete DDC0003Test.php --- .../ORM/Functional/Ticket/DDC0003Test.php | 104 ------------------ 1 file changed, 104 deletions(-) delete mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php deleted file mode 100644 index e0468cea9..000000000 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC0003Test.php +++ /dev/null @@ -1,104 +0,0 @@ - - */ -class DDC0003Test 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->assertEquals('integer', gettype($profileStatus->getId())); - $this->assertEquals(1, $profileStatus->getId()); - } -} - -/** - * @Entity @Table(name="ddc0003_journalist") - */ -class Journalist extends Participant -{ -} - -/** - * @Entity @Table(name="ddc0003_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="ddc0003_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 -{ - -} From 40849f8ae147dfae721a0e68b0c4ed79ed312b4d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 11 Nov 2014 23:40:19 +0100 Subject: [PATCH 4/6] #1086 - Minor CS fixes applied to the test case (simplifying) --- .../ORM/Functional/Ticket/DDC3223Test.php | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php index f3d65f864..5677075dd 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3223Test.php @@ -43,9 +43,7 @@ class DDC3223Test extends OrmFunctionalTestCase } } -/** - * @Entity @Table(name="ddc3223_journalist") - */ +/** @Entity @Table(name="ddc3223_journalist") */ class Journalist extends Participant { } @@ -60,15 +58,10 @@ class Journalist extends Participant */ class Participant { - /** - * @Id @Column(type="integer") - * @GeneratedValue - */ + /** @Id @Column(type="integer") @GeneratedValue */ public $id; - /** - * @ManyToOne(targetEntity="ProfileStatus") - */ + /** @ManyToOne(targetEntity="ProfileStatus") */ public $profileStatus; } @@ -82,10 +75,7 @@ class Participant */ class Status { - /** - * @Id @Column(type="integer") - * @GeneratedValue(strategy="AUTO") - */ + /** @Id @Column(type="integer") @GeneratedValue(strategy="AUTO") */ private $id; public function getId() @@ -99,5 +89,4 @@ class Status */ class ProfileStatus extends Status { - } From f1170c84a4ac6df6b96977f8ae040c3054e7bdbb Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Tue, 11 Nov 2014 23:41:04 +0100 Subject: [PATCH 5/6] #1086 - Passing type information when building meta-mappings for JTI and STI inheritances --- .../AbstractEntityInheritancePersister.php | 6 ++++-- .../Entity/JoinedSubclassPersister.php | 18 ++++++++++++++++-- .../Persisters/Entity/SingleTablePersister.php | 10 +++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) 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..605d26a6e 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -457,7 +457,14 @@ 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, + $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + ); } } @@ -495,7 +502,14 @@ 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, + $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + ); } } } diff --git a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php index d0148f9cf..cf86c6d4d 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/SingleTablePersister.php @@ -88,7 +88,15 @@ 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, + $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + ); } } } From f13b085582e3a322678fc82116693a0002df3bb3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Sat, 17 Jan 2015 08:14:04 +0100 Subject: [PATCH 6/6] Using `PersisterHelper` instead of the unreliable `ClassMetadataInfo#getTypeOfColumn()` --- .../Persisters/Entity/JoinedSubclassPersister.php | 13 +++++++++++-- .../ORM/Persisters/Entity/SingleTablePersister.php | 7 ++++++- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index 605d26a6e..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 @@ -463,7 +464,11 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $tableAlias, $srcColumn, $className, - $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + PersisterHelper::getTypeOfColumn( + $mapping['sourceToTargetKeyColumns'][$srcColumn], + $targetClass, + $this->em + ) ); } } @@ -508,7 +513,11 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister $tableAlias, $srcColumn, $className, - $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + 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 cf86c6d4d..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 @@ -95,7 +96,11 @@ class SingleTablePersister extends AbstractEntityInheritancePersister $tableAlias, $srcColumn, $className, - $targetClass->getTypeOfColumn($mapping['sourceToTargetKeyColumns'][$srcColumn]) + PersisterHelper::getTypeOfColumn( + $mapping['sourceToTargetKeyColumns'][$srcColumn], + $targetClass, + $this->em + ) ); } }