Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

[DDC-1209] Fixed custom object types as @Id #74

Merged
merged 2 commits into from almost 3 years ago

2 participants

Michael Ridgway Guilherme Blanco
Guilherme Blanco guilhermeblanco merged commit 98bc3c4 into from June 16, 2011
Guilherme Blanco guilhermeblanco closed this June 16, 2011
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 2 unique commits by 1 author.

Jun 15, 2011
Michael Ridgway DDC-1209 tests da2d83f
Jun 16, 2011
Michael Ridgway Made DDC-1209 test pass d1106a7
This page is out of date. Refresh to see the latest.
4  lib/Doctrine/ORM/Id/AssignedGenerator.php
@@ -49,7 +49,7 @@ public function generate(EntityManager $em, $entity)
49 49
             foreach ($idFields as $idField) {
50 50
                 $value = $class->reflFields[$idField]->getValue($entity);
51 51
                 if (isset($value)) {
52  
-                    if (is_object($value)) {
  52
+                    if (isset($class->associationMappings[$idField])) {
53 53
                         if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
54 54
                             throw ORMException::entityMissingForeignAssignedId($entity, $value);
55 55
                         }
@@ -67,7 +67,7 @@ public function generate(EntityManager $em, $entity)
67 67
             $idField = $class->identifier[0];
68 68
             $value = $class->reflFields[$idField]->getValue($entity);
69 69
             if (isset($value)) {
70  
-                if (is_object($value)) {
  70
+                if (isset($class->associationMappings[$idField])) {
71 71
                     if (!$em->getUnitOfWork()->isInIdentityMap($value)) {
72 72
                         throw ORMException::entityMissingForeignAssignedId($entity, $value);
73 73
                     }
2  lib/Doctrine/ORM/ORMException.php
@@ -38,7 +38,7 @@ public static function missingMappingDriverImpl()
38 38
     public static function entityMissingForeignAssignedId($entity, $relatedEntity)
39 39
     {
40 40
         return new self(
41  
-            "Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntityClass) . ", " .
  41
+            "Entity of type " . get_class($entity) . " has identity through a foreign entity " . get_class($relatedEntity) . ", " .
42 42
             "however this entity has no ientity itself. You have to call EntityManager#persist() on the related entity " .
43 43
             "and make sure it an identifier was generated before trying to persist '" . get_class($entity) . "'. In case " .
44 44
             "of Post Insert ID Generation (such as MySQL Auto-Increment or PostgreSQL SERIAL) this means you have to call " .
125  tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1209Test.php
... ...
@@ -0,0 +1,125 @@
  1
+<?php
  2
+
  3
+namespace Doctrine\Tests\ORM\Functional\Ticket;
  4
+
  5
+use Doctrine\Common\Collections\ArrayCollection;
  6
+
  7
+require_once __DIR__ . '/../../../TestInit.php';
  8
+
  9
+class DDC1209Test extends \Doctrine\Tests\OrmFunctionalTestCase
  10
+{
  11
+    protected function setUp()
  12
+    {
  13
+        parent::setUp();
  14
+        try {
  15
+            $this->_schemaTool->createSchema(array(
  16
+                $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_1'),
  17
+                $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_2'),
  18
+                $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1209_3')
  19
+            ));
  20
+        } catch(\Exception $e) {
  21
+        }
  22
+    }
  23
+
  24
+    /**
  25
+     * @group DDC-1209
  26
+     */
  27
+    public function testIdentifierCanHaveCustomType()
  28
+    {
  29
+        $this->_em->persist(new DDC1209_3());
  30
+        $this->_em->flush();
  31
+    }
  32
+
  33
+    /**
  34
+     * @group DDC-1209
  35
+     */
  36
+    public function testCompositeIdentifierCanHaveCustomType()
  37
+    {
  38
+        $future1 = new DDC1209_1();
  39
+        $this->_em->persist($future1);
  40
+
  41
+        $this->_em->flush();
  42
+
  43
+        $future2 = new DDC1209_2($future1);
  44
+        $this->_em->persist($future2);
  45
+
  46
+        $this->_em->flush();
  47
+    }
  48
+}
  49
+
  50
+/**
  51
+ * @Entity
  52
+ */
  53
+class DDC1209_1
  54
+{
  55
+    /**
  56
+     * @Id @GeneratedValue @Column(type="integer")
  57
+     */
  58
+    private $id;
  59
+
  60
+    public function getId()
  61
+    {
  62
+        return $this->id;
  63
+    }
  64
+}
  65
+
  66
+/**
  67
+ * @Entity
  68
+ */
  69
+class DDC1209_2
  70
+{
  71
+    /**
  72
+     *  @Id
  73
+     *  @ManyToOne(targetEntity="DDC1209_1")
  74
+     *  @JoinColumn(referencedColumnName="id", nullable=false)
  75
+     */
  76
+    private $future1;
  77
+    /**
  78
+     *  @Id
  79
+     *  @Column(type="datetime", nullable=false)
  80
+     */
  81
+    private $starting_datetime;
  82
+    /**
  83
+     *  @Id
  84
+     *  @Column(type="datetime", nullable=false)
  85
+     */
  86
+    private $during_datetime;
  87
+    /**
  88
+     *  @Id
  89
+     *  @Column(type="datetime", nullable=false)
  90
+     */
  91
+    private $ending_datetime;
  92
+
  93
+    public function __construct(DDC1209_1 $future1)
  94
+    {
  95
+        $this->future1 = $future1;
  96
+        $this->starting_datetime = new DateTime2();
  97
+        $this->during_datetime = new DateTime2();
  98
+        $this->ending_datetime = new DateTime2();
  99
+    }
  100
+}
  101
+
  102
+/**
  103
+ * @Entity
  104
+ */
  105
+class DDC1209_3
  106
+{
  107
+    /**
  108
+     * @Id
  109
+     * @Column(type="datetime")
  110
+     */
  111
+    private $date;
  112
+
  113
+    public function __construct()
  114
+    {
  115
+        $this->date = new DateTime2();
  116
+    }
  117
+}
  118
+
  119
+class DateTime2 extends \DateTime
  120
+{
  121
+    public function __toString()
  122
+    {
  123
+        return $this->format('Y');
  124
+    }
  125
+}
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.