Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-2119

Problem with inheritance type: INHERITANCE_TYPE_NONE and INHERITANCE_TYPE_TABLE_PER_CLASS

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.1
    • Fix Version/s: None
    • Component/s: DQL, Tools
    • Labels:

      Description

      I tried to create inheritance entities with save policy table per class.
      Simple fileds was created normally, but a field with ManyToOne type was lost.

      I had found a solution.

      In Doctrine\ORM\Tools\SchemaTool
      ...

      private function _gatherRelationsSql($class, $table, $schema)
          {
              foreach ($class->associationMappings as $fieldName => $mapping) {
      
                 // if (isset($mapping['inherited'])) { // - old version
      
      	/**
                   * SSW
                   * It's the solution
                   */
      	if (isset($mapping['inherited']) && !$class->isInheritanceTypeNone() && !$class->isInheritanceTypeTablePerClass() ) {
                      continue;
                  }            
      
                  $foreignClass = $this->_em->getClassMetadata($mapping['targetEntity']);
      ...
      

      But it was enough. In DQL query a simple query was made wrong.

      I had found a solution again.
      In Doctrine\ORM\Query\SqlWalker
      ...

      public function walkSelectExpression($selectExpression)
      ...
      
                      // original => if (isset($mapping['inherited'])){
                      // It's the solution
                      if (isset($mapping['inherited']) && !$class->isInheritanceTypeNone() && !$class->isInheritanceTypeTablePerClass()) {
                          $tableName = $this->_em->getClassMetadata($mapping['inherited'])->table['name'];
                      } else {
                          $tableName = $class->table['name'];
                      }
      ...
      

      This problems are topical for inheritance type: INHERITANCE_TYPE_NONE and INHERITANCE_TYPE_TABLE_PER_CLASS.

      I don't know, may be my solutions are wrong. But some programmers want to correctly work with INHERITANCE_TYPE_TABLE_PER_CLASS.

      Sorry for my english.

      1. dump.sql
        5 kB
        SergSW
      2. SSWTestBundle.rar
        5 kB
        SergSW

        Activity

        Hide
        Marco Pivetta added a comment -

        SergSW news?

        Show
        Marco Pivetta added a comment - SergSW news?
        Hide
        Benjamin Eberlei added a comment -

        What version of 2.1 are you using? We don't actually support 2.1 anymore. Inheritance has always worked as used in hundrets of unit-tests, this changes look quite major a bug to have been missed before. I can't really explain whats happening here.

        Show
        Benjamin Eberlei added a comment - What version of 2.1 are you using? We don't actually support 2.1 anymore. Inheritance has always worked as used in hundrets of unit-tests, this changes look quite major a bug to have been missed before. I can't really explain whats happening here.
        Hide
        Benjamin Eberlei added a comment -

        Adjusted example formatting, don't apologize for your English, thanks for the report!

        Show
        Benjamin Eberlei added a comment - Adjusted example formatting, don't apologize for your English, thanks for the report!
        Hide
        SergSW added a comment -

        MySQL dump

        Show
        SergSW added a comment - MySQL dump
        Hide
        SergSW added a comment -

        I install the Symfony v2.0.18. and made small TestBundle.
        I made schema database, by CLI "console doctrine:schema:update --force"
        Result: Database schema updated successfully!
        But I saw that I lost a field 'user_id' in a table 'AttachTree' (see Attach)

        Show
        SergSW added a comment - I install the Symfony v2.0.18. and made small TestBundle. I made schema database, by CLI "console doctrine:schema:update --force" Result: Database schema updated successfully! But I saw that I lost a field 'user_id' in a table 'AttachTree' (see Attach)
        Hide
        SergSW added a comment -

        SSW/TestBundle with the problem

        Show
        SergSW added a comment - SSW/TestBundle with the problem
        Hide
        Fabio B. Silva added a comment -

        Hi SergSW

        Could you try to write a failing test case ?

        Thanks

        Show
        Fabio B. Silva added a comment - Hi SergSW Could you try to write a failing test case ? Thanks

          People

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

            Dates

            • Created:
              Updated: