Ticket #987 (closed defect: fixed)

Opened 15 months ago

Last modified 14 months ago

Querying with Doctrine_View fails

Reported by: sigma Owned by: romanb
Priority: major Milestone: 0.11.0
Component: Query/Hydration Version: 0.10.0
Severity: Keywords:
Cc: Has Test:
Status: Has Patch:

Description

used configuration:

  • Doctrine 0.10.4
  • PHP 5.2.5 as Apache module

Example, that throws Doctrine_Query_Exception:

// creating the query
$q = Doctrine_Query::create();
$q->from('Person p, p.PersonType');

// creating the view
$view = new Doctrine_View( $q, 'view_person2person_type' );
$view->create();

// creating the query
$q = Doctrine_Query::create();
$q->from('Person p, p.PersonType');

// creating view object for querying
$view = new Doctrine_View( $q, 'view_person2person_type' );

// executes view
$coll = $view->execute();


// class Person with relation to PersonType
class Person extends Doctrine_Record {

    public function setTableDefinition() {
        $this->setTableName('person');
        $this->hasColumn( 'id', 'integer', 11, array('primary' => true, 'notnull' => true, 'autoincrement' => true) );
        $this->hasColumn( 'person_type_id', 'integer', 10, array('notblank' => true, 'primary' => false, 'notnull' => true, 'autoincrement' => false) );
        $this->hasColumn( 'gender', 'integer', 1, array('notblank' => true, 'primary' => false, 'notnull' => true, 'autoincrement' => false) );
        $this->hasColumn( 'firstname', 'string', 30, array('notblank' => true, 'primary' => false, 'notnull' => true, 'autoincrement' => false) );
        $this->hasColumn( 'lastname', 'string', 30, array('notblank' => true, 'primary' => false, 'notnull' => true, 'autoincrement' => false) );
    }

    public function setUp() {
        parent::setUp();

        $this->hasOne( 'PersonType', array('local' => 'person_type_id',
          'foreign' => 'id',
          'onUpdate' => 'CASCADE',
        ) );
    }
}

// class PersonType with relation to Person
class PersonType extends Doctrine_Record {

    public function setTableDefinition() {
        $this->setTableName('person_type');
        $this->hasColumn( 'id', 'integer', 11, array('primary' => true, 'notnull' => true, 'autoincrement' => true) );
        $this->hasColumn( 'name', 'string', 30, array('notblank' => true, 'primary' => false, 'notnull' => true, 'autoincrement' => false) );

    }

    public function setUp() {
        parent::setUp();

        $this->hasMany( 'Person', array('local' => 'id',
          'foreign' => 'person_type_id',
         ) );
    }
}

View execution throws exception:

Doctrine_Query_Exception' with message 'Root component not initialized.' in ../library/Doctrine/Query/Abstract.php:805
Stack trace:
#0 ../library/Doctrine/Query/Abstract.php(514): Doctrine_Query_Abstract->getRoot()
#1 ../library/Doctrine/Query/Abstract.php(904): Doctrine_Query_Abstract->convertEnums(Array)
#2 ../library/Doctrine/Query/Abstract.php(957): Doctrine_Query_Abstract->_execute(Array)
#3 ../library/Doctrine/View.php(155): Doctrine_Query_Abstract->execute()

If I execute the query without using a view, it works...

Have I done something terribly wrong?

Greets

from

Sigma

Change History

Changed 15 months ago by sigma

  • summary changed from View fails to Querying with Doctrine_View fails

Changed 14 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4303]) fixes #987

Note: See TracTickets for help on using tickets.