Changeset 4336

Show
Ignore:
Timestamp:
05/06/08 10:20:42 (8 months ago)
Author:
romanb
Message:

Object hydration now properly initializes collections.

Location:
branches/0.11
Files:
1 added
6 modified

Legend:

Unmodified
Added
Removed
  • branches/0.11/lib/Doctrine/Hydrator.php

    r4263 r4336  
    108108            $listeners[$componentName] = $data['table']->getRecordListener(); 
    109109            $identifierMap[$dqlAlias] = array(); 
    110             $prev[$dqlAlias] = array(); 
     110            $prev[$dqlAlias] = null; 
    111111            $idTemplate[$dqlAlias] = ''; 
    112112        } 
  • branches/0.11/lib/Doctrine/Hydrator/RecordDriver.php

    r4332 r4336  
    3737    protected $_collections = array(); 
    3838    protected $_tables = array(); 
     39    private $_initializedRelations = array(); 
    3940 
    4041    public function getElementCollection($component) 
     
    5556    public function initRelated($record, $name) 
    5657    { 
     58        if ( ! isset($this->_initializedRelations[$record->getOid()][$name])) { 
     59            $relation = $record->getTable()->getRelation($name); 
     60            $coll = new Doctrine_Collection($relation->getTable()->getComponentName()); 
     61            $coll->setReference($record, $relation); 
     62            $record[$name] = $coll; 
     63            $this->_initializedRelations[$record->getOid()][$name] = true; 
     64        } 
    5765        return true; 
    58         /* 
    59         if ( ! is_array($record)) { 
    60             $record[$name]; 
    61             return true; 
    62         } 
    63         return false; 
    64         */ 
    6566    } 
    6667     
     
    125126            $table->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, true); 
    126127        } 
     128        $this->_initializedRelations = null; 
     129        $this->_collections = null; 
     130        $this->_tables = null; 
    127131    } 
    128132     
  • branches/0.11/lib/Doctrine/Record.php

    r4332 r4336  
    950950 
    951951        // one-to-many or one-to-one relation 
    952         if ($rel instanceof Doctrine_Relation_ForeignKey || 
    953             $rel instanceof Doctrine_Relation_LocalKey) { 
     952        if ($rel instanceof Doctrine_Relation_ForeignKey || $rel instanceof Doctrine_Relation_LocalKey) { 
    954953            if ( ! $rel->isOneToOne()) { 
    955954                // one-to-many relation found 
  • branches/0.11/tests/Query/LimitTestCase.php

    r3884 r4336  
    206206        $q = new Doctrine_Query(); 
    207207        $q->from('User.Group')->limit(5); 
    208  
     208         
    209209        $users = $q->execute(); 
    210210 
     
    212212         
    213213        $user = $this->objTable->find(5); 
     214         
    214215        $user->Group[1]->name = "Tough guys inc."; 
     216         
    215217        $user->Group[2]->name = "Terminators"; 
    216218         
     
    225227 
    226228        $this->connection->flush(); 
    227  
     229         
    228230        $this->assertEqual($user->Group[0]->name, "Action Actors"); 
    229231        $this->assertEqual(count($user->Group), 3); 
    230  
    231  
    232  
    233         $q = new Doctrine_Query(); 
    234         $q->from("User")->where("User.Group.id = ?")->orderby("User.id ASC")->limit(5); 
    235  
    236  
     232         
     233        $q = new Doctrine_Query(); 
     234        $q->from("User")->where("User.Group.id = ?")->orderby("User.id ASC")->limit(5);        
     235              
    237236        $users = $q->execute(array($user->Group[1]->id)); 
    238  
     237         
    239238        $this->assertEqual($users->count(), 3); 
    240  
     239         
    241240        $this->connection->clear(); 
    242241        $q = new Doctrine_Query(); 
  • branches/0.11/tests/Record/SynchronizeTestCase.php

    r3884 r4336  
    8787        $userArray['Phonenumber'][] = array('phonenumber' => '333 238'); 
    8888 
     89 
    8990        $user->synchronizeWithArray($userArray); 
     91         
    9092        $this->assertEqual($user->Phonenumber->count(), 2); 
    9193        $this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238'); 
     
    9698    { 
    9799        $user = Doctrine_Query::create()->from('User u, u.Email, u.Phonenumber')->fetchOne(); 
     100         
    98101        $this->assertEqual($user->Phonenumber->count(), 2); 
    99102        $this->assertEqual($user->Phonenumber[1]->phonenumber, '333 238'); 
  • branches/0.11/tests/run.php

    r4334 r4336  
    169169$core->addTestCase(new Doctrine_Collection_Snapshot_TestCase()); 
    170170$core->addTestCase(new Doctrine_Hydrate_FetchMode_TestCase()); 
     171$core->addTestCase(new Doctrine_Hydrate_CollectionInitialization_TestCase()); 
    171172$core->addTestCase(new Doctrine_Tokenizer_TestCase()); 
    172173$core->addTestCase(new Doctrine_BatchIterator_TestCase());