Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-1218

Generator disappear with mappedSuperclass and in others common inheritance's cases

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-BETA4
    • Fix Version/s: 2.1
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony

      Description

      With mapped superclass the id lost autoincrement. I've test with yaml and annotation this is the same.

      An example with yaml entities :

       
      Document:
        type: mappedSuperclass
        fields:
          mimetype: { type: string, length: 255 }
          filename: { type: string, length: 255 }
      
      Image:
        type: entity
        fields:
          id: { type: integer, id: true, generator: { strategy: AUTO } }
      

      The id in the table Image lost autoincrement.

        Activity

        Hide
        Nicolas added a comment - - edited

        The problem is in file doctrine/lib/Doctrine/ORM/Mapping, a solution, with just one change could be
        :

            protected function loadMetadata($name)
            {
                if ( ! $this->initialized) {
        ...
                // Move down the hierarchy of parent classes, starting from the topmost class
        ...
                    // Invoke driver
                    try {
                        $this->driver->loadMetadataForClass($className, $class);
                    } catch (ReflectionException $e) {
                        throw MappingException::reflectionFailure($className, $e);
                    }
        //Change
                    if ($parent) {
        //To
                    if ($parent && ! $parent->isInheritanceTypeNone()) {
        //EndChange
                        if ($parent->isIdGeneratorSequence()) {
        ...
                }
        
        Show
        Nicolas added a comment - - edited The problem is in file doctrine/lib/Doctrine/ORM/Mapping, a solution, with just one change could be : protected function loadMetadata($name) { if ( ! $ this ->initialized) { ... // Move down the hierarchy of parent classes, starting from the topmost class ... // Invoke driver try { $ this ->driver->loadMetadataForClass($className, $class); } catch (ReflectionException $e) { throw MappingException::reflectionFailure($className, $e); } //Change if ($parent) { //To if ($parent && ! $parent->isInheritanceTypeNone()) { //EndChange if ($parent->isIdGeneratorSequence()) { ... }
        Hide
        Nicolas added a comment - - edited

        I have seen the resolution in doctrine later version, so i hesitate to close this issue.

        But i'm sure that the solution in place will not resolve all situation.

        By example, if the superclass isn't mapped but an entity with joined, this doesn't work properly, and you lost the id and the generator of the childclass. Another exemple, you want a mapped with generator, and subclass which don't indicate id, you can't the generator isn't include, and the id is required in the subclass.

        The code actually work just for same table proposition, and not good, because with same table you must indicate an not used id in the child class ( why an id is an obligation!!!, Sql permit to have table without id).

        If somebody read this, i propose a solution for inherited class with another schema,

        Each propositions are with a class inheriting from superclass :

        Schema for joinedclass.

        In this case generator are leave in the same functions

        table_class
          class_id -> *self generator*
        table_link
          class_id
          class_discriminent
          superclass_id
        table_superclass
          superclass_id -> *self generator*
        

        or better and closest from the actual solution ( with obligation to have different id name)

        table_class
          class_id -> *self generator*
          superclass_id
        table_superclass
          superclass_id -> *self generator*
          discriminator
        

        Schema for same table

        Not exactly the actual behavior but very near

        table_class
           class_id autogenerate (or not exist)
           superclass_id (autogenerate with concatenation class_id and discr or not exit)
        

        The better for me :

        table_class
            superclass_id
        

        Schema for mapped

        table_class
          class_id  <--- if exist (not obligatory)
          superclass_id <--- if class_id not exist, the generator from superclass_id
                                            if class_id exist, the generator from class_id
        

        Even with there ideas, the possibility to have more than one generator method could be usefull. (i know that autoincrement can be use just one time). A solution, could be to add generator to field an not to entity in a first time, and treat generator at the end of the process not in the same place that the fields.

        So if you read this thank and aufwiedersehen.

        Show
        Nicolas added a comment - - edited I have seen the resolution in doctrine later version, so i hesitate to close this issue . But i'm sure that the solution in place will not resolve all situation . By example, if the superclass isn't mapped but an entity with joined, this doesn't work properly, and you lost the id and the generator of the childclass. Another exemple, you want a mapped with generator, and subclass which don't indicate id, you can't the generator isn't include, and the id is required in the subclass. The code actually work just for same table proposition, and not good, because with same table you must indicate an not used id in the child class ( why an id is an obligation!!!, Sql permit to have table without id). If somebody read this, i propose a solution for inherited class with another schema, Each propositions are with a class inheriting from superclass : Schema for joinedclass. In this case generator are leave in the same functions table_class class_id -> *self generator* table_link class_id class_discriminent superclass_id table_superclass superclass_id -> *self generator* or better and closest from the actual solution ( with obligation to have different id name) table_class class_id -> *self generator* superclass_id table_superclass superclass_id -> *self generator* discriminator Schema for same table Not exactly the actual behavior but very near table_class class_id autogenerate (or not exist) superclass_id (autogenerate with concatenation class_id and discr or not exit) The better for me : table_class superclass_id Schema for mapped table_class class_id <--- if exist (not obligatory) superclass_id <--- if class_id not exist, the generator from superclass_id if class_id exist, the generator from class_id Even with there ideas, the possibility to have more than one generator method could be usefull. (i know that autoincrement can be use just one time). A solution, could be to add generator to field an not to entity in a first time, and treat generator at the end of the process not in the same place that the fields. So if you read this thank and aufwiedersehen.
        Hide
        Menno Holtkamp added a comment -

        This seems to relate to an issue I created at: http://www.doctrine-project.org/jira/browse/DDC-1218

        Show
        Menno Holtkamp added a comment - This seems to relate to an issue I created at: http://www.doctrine-project.org/jira/browse/DDC-1218
        Hide
        Benjamin Eberlei added a comment -

        Fixed

        Show
        Benjamin Eberlei added a comment - Fixed
        Hide
        Nicolas added a comment -

        Thanks

        Show
        Nicolas added a comment - Thanks

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Nicolas
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: