Doctrine 1
  1. Doctrine 1
  2. DC-356

Error in self referencing (nest relations) and tableName.

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: None
    • Labels:
      None
    • Environment:
      Linux, php 5.2.10, apache 2.2.12

      Description

      I have this schema:

      1. Interface
        Interfaz:
        tableName: YT_INTERFAZ
        columns:
        cinterfaz: { type: integer, notnull: true, primary: true, autoincrement: true }

        relations:
        Conexiones:
        class: Interfaz
        local: cinterfazsrc
        foreign: cinterfazdst
        refClass: Conexion
        equal: true

      #Link
      Conexion:
      tableName: YT_CONEXION
      columns:
      cinterfazsrc:

      { type: integer, primary: true }

      cinterfazdst:

      { type: integer, primary: true }

      When I try to get $interfaz->Conexiones, I get this message:

      Notice: Undefined index: yt_interfaz in /home/sergio/Proyectos/syc/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Hydrator/Graph.php on line 288

      Notice: Undefined index: in /home/sergio/Proyectos/syc/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Hydrator/Graph.php on line 289

      Fatal error: Call to a member function getFieldName() on a non-object in /home/sergio/Proyectos/syc/lib/vendor/symfony/lib/plugins/sfDoctrinePlugin/lib/vendor/doctrine/Doctrine/Hydrator/Graph.php on line 290

      But If I remove tableName fields in schema declaration, it works perfectly. The name of tableName don't matters, if you use it, it fails.

        Activity

        Hide
        Jay Klehr added a comment -

        We've encountered this as well, tried a lot of different things in our models/schema to get around it, but nothing worked.

        Made a test case here: https://github.com/diablomedia/doctrine1/blob/master/tests/Ticket/DC356TestCase.php

        Modified the doctrine core as suggested by Danny, but this change causes other Doctrine test to fail (Particularly tests/TableTestCase.php).

        Show
        Jay Klehr added a comment - We've encountered this as well, tried a lot of different things in our models/schema to get around it, but nothing worked. Made a test case here: https://github.com/diablomedia/doctrine1/blob/master/tests/Ticket/DC356TestCase.php Modified the doctrine core as suggested by Danny, but this change causes other Doctrine test to fail (Particularly tests/TableTestCase.php).
        Hide
        Danny Kopping added a comment -

        I've just tested this scenario in as many different possible combinations as I could think of (all tables uppercase/PascalCase, all tables lowercase, some Pascal, some lowercase) and just by removing the "strtolower" function, the issue seems to be resolved.

        Show
        Danny Kopping added a comment - I've just tested this scenario in as many different possible combinations as I could think of (all tables uppercase/PascalCase, all tables lowercase, some Pascal, some lowercase) and just by removing the "strtolower" function, the issue seems to be resolved.
        Hide
        Danny Kopping added a comment -

        As Klaas mentions, this function incorrectly assumes that all databases will be named using lowercase letters.

        The problem arises in the following line:
        $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];

        If one removes the "strtolower" function call, it will work for tables named with uppercase letters, but this is obviously quite an inelegant solution.

        Could you suggest an alternative solution? I'll be happy to make the change, test it and issue a pull request in GitHub

        Show
        Danny Kopping added a comment - As Klaas mentions, this function incorrectly assumes that all databases will be named using lowercase letters. The problem arises in the following line: $cache [$key] ['dqlAlias'] = $this->_tableAliases [strtolower(implode('__', $e))] ; If one removes the "strtolower" function call, it will work for tables named with uppercase letters, but this is obviously quite an inelegant solution. Could you suggest an alternative solution? I'll be happy to make the change, test it and issue a pull request in GitHub
        Hide
        Klaas van der Weij added a comment -

        This aching issue - as I traced the cord back to the wall - appears to originate from the fact that I use UPPERCASES in the names of my databas tables. When I user all lowercases: no problem. Hence it worked on my WAMP server (Windows just lowercases it all). Even when I so much as start the entity-table which an UPPERCASE: bang! Fatal error.

        This is not logical and, I presume, is a definite bug.

        Please, oh please fix this ..

        Show
        Klaas van der Weij added a comment - This aching issue - as I traced the cord back to the wall - appears to originate from the fact that I use UPPERCASES in the names of my databas tables. When I user all lowercases: no problem. Hence it worked on my WAMP server (Windows just lowercases it all). Even when I so much as start the entity-table which an UPPERCASE: bang! Fatal error. This is not logical and, I presume, is a definite bug. Please, oh please fix this ..
        Hide
        Klaas van der Weij added a comment -

        Same story over here. Same error with the following non-equal nest relation:

        <?php
        
        class TXCRDataNodeCRDataNode extends Doctrine_Record
        {
            public function setTableDefinition() {
                $this->setTableName('x_CRDataNode_CRDataNode');
                $this->hasColumn('childNodeID', 'integer', 4, array(
                     'type' => 'integer',
                     'length' => 4,
                     'fixed' => false,
                     'unsigned' => false,
                     'primary' => true,
                     'autoincrement' => false,
                     ));
                $this->hasColumn('parentNodeID', 'integer', 4, array(
                     'type' => 'integer',
                     'length' => 4,
                     'fixed' => false,
                     'unsigned' => false,
                     'primary' => true,
                     'autoincrement' => false,
                     ));
            }
        
            public function setUp() {
                parent::setUp();
                $this->hasOne('TCRDataNode as child', array(
                     'local' => 'childNodeID',
                     'foreign' => 'dataNodeID'));
                $this->hasOne('TCRDataNode as parent', array(
                     'local' => 'parentNodeID',
                     'foreign' => 'dataNodeID'));
            }
        }
        
        class TCRDataNode extends Doctrine_Record
        {
            public function setTableDefinition() {
                $this->setTableName('CRDataNode');
                $this->hasColumn('dataNodeID', 'integer', 4, array(
                     'type' => 'integer',
                     'length' => 4,
                     'fixed' => false,
                     'unsigned' => false,
                     'primary' => true,
                     'autoincrement' => false,
                     ));
                $this->hasColumn('value', 'string', 255, array(
                     'type' => 'string',
                     'length' => 255,
                     'fixed' => false,
                     'unsigned' => false,
                     'primary' => false,
                     'notnull' => false,
                     'autoincrement' => false,
                     ));
            }
            public function setUp() {
                $this->hasMany('TCRDataNode as childNodes', array(
                    'local' => 'parentNodeID',
                    'foreign' => 'childNodeID',
                    'refClass' => 'TXCRDataNodeCRDataNode'));
                $this->hasMany('TCRDataNode as parentNodes', array(
                    'local' => 'childNodeID',
                    'foreign' => 'parentNodeID',
                    'refClass' => 'TXCRDataNodeCRDataNode'));
            }
        }
        
        $dn = Doctrine_Core::getTable('TCRDataNode')->find(5300);
        
        ?>
        

        .. and then when I ..

        <?php
        
        $pn = $dn->parentNodes;
        
        ?>
        

        .. it goes like:

        Notice: Undefined index: crdatanode in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 288

        Notice: Undefined index: in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 289

        Fatal error: Call to a member function getFieldName() on a non-object in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 290

        Using Doctrine 1.2.2

        It seemed like the same thing as presented in the documentation

        Show
        Klaas van der Weij added a comment - Same story over here. Same error with the following non-equal nest relation: <?php class TXCRDataNodeCRDataNode extends Doctrine_Record { public function setTableDefinition() { $ this ->setTableName('x_CRDataNode_CRDataNode'); $ this ->hasColumn('childNodeID', 'integer', 4, array( 'type' => 'integer', 'length' => 4, 'fixed' => false , 'unsigned' => false , 'primary' => true , 'autoincrement' => false , )); $ this ->hasColumn('parentNodeID', 'integer', 4, array( 'type' => 'integer', 'length' => 4, 'fixed' => false , 'unsigned' => false , 'primary' => true , 'autoincrement' => false , )); } public function setUp() { parent::setUp(); $ this ->hasOne('TCRDataNode as child', array( 'local' => 'childNodeID', 'foreign' => 'dataNodeID')); $ this ->hasOne('TCRDataNode as parent', array( 'local' => 'parentNodeID', 'foreign' => 'dataNodeID')); } } class TCRDataNode extends Doctrine_Record { public function setTableDefinition() { $ this ->setTableName('CRDataNode'); $ this ->hasColumn('dataNodeID', 'integer', 4, array( 'type' => 'integer', 'length' => 4, 'fixed' => false , 'unsigned' => false , 'primary' => true , 'autoincrement' => false , )); $ this ->hasColumn('value', 'string', 255, array( 'type' => 'string', 'length' => 255, 'fixed' => false , 'unsigned' => false , 'primary' => false , 'notnull' => false , 'autoincrement' => false , )); } public function setUp() { $ this ->hasMany('TCRDataNode as childNodes', array( 'local' => 'parentNodeID', 'foreign' => 'childNodeID', 'refClass' => 'TXCRDataNodeCRDataNode')); $ this ->hasMany('TCRDataNode as parentNodes', array( 'local' => 'childNodeID', 'foreign' => 'parentNodeID', 'refClass' => 'TXCRDataNodeCRDataNode')); } } $dn = Doctrine_Core::getTable('TCRDataNode')->find(5300); ?> .. and then when I .. <?php $pn = $dn->parentNodes; ?> .. it goes like: Notice: Undefined index: crdatanode in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 288 Notice: Undefined index: in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 289 Fatal error: Call to a member function getFieldName() on a non-object in /home/shared/library/doctrine_1.2.2/Doctrine/Hydrator/Graph.php on line 290 Using Doctrine 1.2.2 It seemed like the same thing as presented in the documentation

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Sergio Gomez
          • Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: