[DC-356] Error in self referencing (nest relations) and tableName. Created: 14/Dec/09  Updated: 17/Jan/13

Status: Open
Project: Doctrine 1
Component/s: None
Affects Version/s: 1.2.1
Fix Version/s: None

Type: Bug Priority: Major
Reporter: Sergio Gomez Assignee: Jonathan H. Wage
Resolution: Unresolved Votes: 2
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.



 Comments   
Comment by Klaas van der Weij [ 15/Feb/11 ]

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

Comment by Klaas van der Weij [ 17/Feb/11 ]

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 ..

Comment by Danny Kopping [ 06/Mar/12 ]

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

Comment by Danny Kopping [ 06/Mar/12 ]

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.

Comment by Jay Klehr [ 17/Jan/13 ]

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).

Generated at Wed Sep 24 04:28:37 UTC 2014 using JIRA 6.2.3#6260-sha1:63ef1d6dac3f4f4d7db4c1effd405ba38ccdc558.