Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1921

Clarify Identifier definition for CTI entities

    Details

    • Type: Documentation Documentation
    • Status: Open
    • Priority: Minor Minor
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Documentation
    • Security Level: All
    • Labels:
      None

      Description

      Hello,

      Reference Guide topic 4.8 Identifers/Primary Keys(http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifiers-primary-keys) states that: "Every entity class needs an identifier/primary key."

      However, example in topic 7.3. Class Table Inheritance (http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/inheritance-mapping.html#class-table-inheritance) doesn't contain any definitions for Ids.

      Consider following code:

      /**
       * @Entity
       * @InheritanceType("JOINED")
       * @DiscriminatorColumn(name="discr", type="string")
       * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
       */
      class Person
      {
          /** @Id @Column(type="integer") */
          private $id;
      
          public function getId() {
              return $this->id;
          }
      }
      
      /** @Entity */
      class Employee extends Person
      {
          /** @Id @Column(type="integer") */
          private $id;
      
          // Overrides parent to retrieve private
          public function getId() {
              return $this->id;
          }
      }
      
      // create instances and $em->persist(...)
      
      // $person instanceof Person
      $person->getId(); // Returns id.
      
      // $employee instanceof Employee
      $employee->getId(); // Returns null. Private $id in subclass isn't assigned.
      

      Please clarify correct use of identifiers in CTI subclass entities. Should subclasses contain any definitions of identifiers?

      Thank you!

      Ludek

        Activity

        Ludek Stepan created issue -
        Ludek Stepan made changes -
        Field Original Value New Value
        Description Hello,

        Reference Guide topic 4.8 Identifers/Primary Keys(http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifiers-primary-keys) states that: "Every entity class needs an identifier/primary key."

        However, example in topic 7.3. Class Table Inheritance (http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/inheritance-mapping.html#class-table-inheritance) doesn't contain any definitions for Ids.

        Consider following code:

        /**
         * @Entity
         * @InheritanceType("JOINED")
         * @DiscriminatorColumn(name="discr", type="string")
         * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
         */
        class Person
        {
            /** @Id @Column(type="integer") */
            private $id;

            public function getId() {
                return $this->id;
            }
        }

        /** @Entity */
        class Employee extends Person
        {
            /** @Id @Column(type="integer") */
            private $id;

            // Overrides parent to retrieve private
            public function getId() {
                return $this->id;
            }
        }

        // create instances and $em->persist(...)

        // $person instanceof Person
        $person->getId(); // Returns id.

        // $employee instanceof Employee
        $employee->getId(); // Returns null. Private $id in subclass isn't assigned.

        Please clarify correct use of identifiers in CTI subclass entities. Should subclasses contain any definitions of identifiers?

        Thank you!

        Ludek
        Hello,

        Reference Guide topic 4.8 Identifers/Primary Keys(http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/reference/basic-mapping.html#identifiers-primary-keys) states that: "Every entity class needs an identifier/primary key."

        However, example in topic 7.3. Class Table Inheritance (http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/inheritance-mapping.html#class-table-inheritance) doesn't contain any definitions for Ids.

        Consider following code:
        {code}
        /**
         * @Entity
         * @InheritanceType("JOINED")
         * @DiscriminatorColumn(name="discr", type="string")
         * @DiscriminatorMap({"person" = "Person", "employee" = "Employee"})
         */
        class Person
        {
            /** @Id @Column(type="integer") */
            private $id;

            public function getId() {
                return $this->id;
            }
        }

        /** @Entity */
        class Employee extends Person
        {
            /** @Id @Column(type="integer") */
            private $id;

            // Overrides parent to retrieve private
            public function getId() {
                return $this->id;
            }
        }

        // create instances and $em->persist(...)

        // $person instanceof Person
        $person->getId(); // Returns id.

        // $employee instanceof Employee
        $employee->getId(); // Returns null. Private $id in subclass isn't assigned.
        {code}
        Please clarify correct use of identifiers in CTI subclass entities. Should subclasses contain any definitions of identifiers?

        Thank you!

        Ludek

        This list may be incomplete, as errors occurred whilst retrieving source from linked applications:

        • Request to http://www.doctrine-project.org/fisheye/ failed: Error in remote call to 'FishEye 0 (http://www.doctrine-project.org/fisheye/)' (http://www.doctrine-project.org/fisheye) [AbstractRestCommand{path='/rest-service-fe/search-v1/crossRepositoryQuery', params={query=DDC-1921, expand=changesets[0:20].revisions[0:29],reviews}, methodType=GET}] : Received status code 503 (Service Temporarily Unavailable)

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Ludek Stepan
          • Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: