Changeset 4889

Show
Ignore:
Timestamp:
09/08/08 19:48:10 (10 months ago)
Author:
romanb
Message:

Fixed #1323. Final adjustments to come from jon.

Location:
branches/1.0
Files:
2 added
8 modified

Legend:

Unmodified
Added
Removed
  • branches/1.0/lib/Doctrine/Collection.php

    r4720 r4889  
    264264 
    265265        if ($relation instanceof Doctrine_Relation_ForeignKey ||  
    266             $relation instanceof Doctrine_Relation_LocalKey) { 
    267  
     266                $relation instanceof Doctrine_Relation_LocalKey) { 
    268267            $this->referenceField = $relation->getForeignFieldName(); 
    269268 
     
    442441        if (isset($this->referenceField)) { 
    443442            $value = $this->reference->get($this->relation->getLocalFieldName()); 
    444  
    445443            if ($value !== null) { 
    446444                $record->set($this->referenceField, $value, false); 
  • branches/1.0/lib/Doctrine/Connection/UnitOfWork.php

    r4886 r4889  
    445445                    $this->saveGraph($assocRecord); 
    446446                } 
     447                // take snapshot of collection state, so that we know when its modified again 
     448                $v->takeSnapshot(); 
    447449            } 
    448450        } 
  • branches/1.0/lib/Doctrine/Relation.php

    r4830 r4889  
    6767                                  'cascade'     => array(), // application-level cascades 
    6868                                  'owningSide'  => false, // whether this is the owning side 
     69                                  'refClassRelation' => null, 
    6970                                  ); 
    7071 
  • branches/1.0/lib/Doctrine/Relation/Nest.php

    r4252 r4889  
    3939     * @return string 
    4040     */ 
    41     public function getRelationDql($count, $context = 'record') 
     41    /*public function getRelationDql($count, $context = 'record') 
    4242    { 
    4343        switch ($context) { 
     
    7373 
    7474        return $dql; 
    75     } 
    76  
    77     /** 
    78     public function fetchRelatedFor(Doctrine_Record $record) 
    79     { 
    80         $id = $record->getIncremented(); 
    81  
    82         if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { 
    83             return new Doctrine_Collection($this->getTable()); 
    84         } else { 
    85             $q = new Doctrine_Query(); 
    86              
    87             $c  = $this->getTable()->getComponentName(); 
    88             $a  = substr($c, 0, 1); 
    89             $c2 = $this->getAssociationTable()->getComponentName(); 
    90             $a2 = substr($c2, 0, 1); 
    91  
    92             $q->from($c) 
    93               ->innerJoin($c . '.' . $c2) 
    94  
    95             $sub = 'SELECT ' . $this->getForeign()  
    96                  . ' FROM '  . $c2 
    97                  . ' WHERE ' . $this->getLocal()  
    98                  . ' = ?'; 
    99         } 
    100     } 
    101     */ 
     75    }*/ 
    10276 
    10377    public function fetchRelatedFor(Doctrine_Record $record) 
    10478    { 
    10579        $id = $record->getIncremented(); 
    106  
    10780 
    10881        if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { 
     
    137110              ->where(implode(' OR ', $condition)); 
    138111            $q->addComponent($tableName,  $record->getTable()->getComponentName()); 
    139             $q->addComponent($assocTable, $record->getTable()->getComponentName(). '.' . $this->getAssociationFactory()->getComponentName()); 
     112             
     113            $path = $record->getTable()->getComponentName(). '.' . $this->getAssociationFactory()->getComponentName(); 
     114            if ($this->definition['refClassRelation']) { 
     115                $path = $record->getTable()->getComponentName(). '.' . $this->definition['refClassRelation']; 
     116            } 
     117            $q->addComponent($assocTable, $path); 
    140118 
    141119            $params = ($this->definition['equal']) ? array($id, $id) : array($id); 
     120            $res = $q->execute($params); 
    142121 
    143             return $q->execute($params); 
     122            return $res; 
    144123        } 
    145124    } 
  • branches/1.0/lib/Doctrine/Relation/Parser.php

    r4586 r4889  
    156156            return $this->_relations[$alias]; 
    157157        } 
    158  
     158        
    159159        if (isset($this->_pending[$alias])) { 
    160160            $def = $this->_pending[$alias]; 
    161161            $identifierColumnNames = $this->_table->getIdentifierColumnNames(); 
    162162            $idColumnName = array_pop($identifierColumnNames); 
    163          
     163             
    164164            // check if reference class name exists 
    165165            // if it does we are dealing with association relation 
     
    167167                $def = $this->completeAssocDefinition($def); 
    168168                $localClasses = array_merge($this->_table->getOption('parents'), array($this->_table->getComponentName())); 
    169  
    170                 if ( ! isset($this->_pending[$def['refClass']]) &&  
    171                      ! isset($this->_relations[$def['refClass']])) { 
     169                 
     170                $backRefRelationName = isset($def['refClassRelation']) ? 
     171                        $def['refClassRelation'] : $def['refClass']; 
     172                if ( ! isset($this->_pending[$backRefRelationName]) && ! isset($this->_relations[$backRefRelationName])) { 
    172173 
    173174                    $parser = $def['refTable']->getRelationParser(); 
     175                     
    174176                    if ( ! $parser->hasRelation($this->_table->getComponentName())) { 
    175177                        $parser->bind($this->_table->getComponentName(), 
     
    181183                    } 
    182184 
    183                     if ( ! $this->hasRelation($def['refClass'])) { 
    184                         $this->bind($def['refClass'], array('type' => Doctrine_Relation::MANY, 
    185                                                             'foreign' => $def['local'], 
    186                                                             'local'   => $idColumnName)); 
     185                    if ( ! $this->hasRelation($backRefRelationName)) { 
     186                        if (in_array($def['class'], $localClasses)) { 
     187                            $this->bind($def['refClass'] . " as " . $backRefRelationName, array( 
     188                                    'type' => Doctrine_Relation::MANY, 
     189                                    'foreign' => $def['foreign'], 
     190                                    'local'   => $idColumnName)); 
     191                        } else { 
     192                            $this->bind($def['refClass'] . " as " . $backRefRelationName, array( 
     193                                    'type' => Doctrine_Relation::MANY, 
     194                                    'foreign' => $def['local'], 
     195                                    'local'   => $idColumnName)); 
     196                        } 
    187197                    } 
    188198                } 
     
    213223                // unset pending relation 
    214224                unset($this->_pending[$alias]); 
    215  
    216225                $this->_relations[$alias] = $rel; 
    217226                return $rel; 
     
    293302                // foreign key not set 
    294303                // try to guess the foreign key 
    295  
    296304                $def['local'] = ($def['foreign'] === $id[0]) ? $id[1] : $id[0]; 
    297305            } 
  • branches/1.0/tests/Query/LimitTestCase.php

    r4794 r4889  
    242242         
    243243        $user2 = $this->objTable->find(4); 
    244         $user2->Group = $user->Group; 
     244        //$user2->Group = $user->Group; 
     245        $user2->Group = new Doctrine_Collection('Group'); 
     246        $user2->Group[] = $user->Group[0]; 
     247        $user2->Group[] = $user->Group[1]; 
     248        $user2->Group[] = $user->Group[2]; 
    245249         
    246250        $user3 = $this->objTable->find(6); 
    247         $user3->Group = $user->Group; 
     251        //$user3->Group = $user->Group; 
     252        $user3->Group = new Doctrine_Collection('Group'); 
     253        $user3->Group[] = $user->Group[0]; 
     254        $user3->Group[] = $user->Group[1]; 
     255        $user3->Group[] = $user->Group[2]; 
    248256 
    249257        $this->assertEqual($user->Group[0]->name, "Action Actors"); 
    250258        $this->assertEqual(count($user->Group), 3); 
     259        $this->assertEqual(count($user2->Group), 3); 
     260        $this->assertEqual(count($user3->Group), 3); 
    251261 
    252262        $this->connection->flush(); 
     
    256266         
    257267        $q = new Doctrine_Query(); 
    258         $q->from("User")->where("User.Group.id = ?")->orderby("User.id ASC")->limit(5);        
    259               
     268        $q->from("User")->where("User.Group.id = ?")->orderby("User.id ASC")->limit(5); 
     269         
    260270        $users = $q->execute(array($user->Group[1]->id)); 
    261271         
  • branches/1.0/tests/Relation/ManyToManyTestCase.php

    r4109 r4889  
    3636            $this->pass(); 
    3737        } catch(Doctrine_Exception $e) { 
     38            echo $e->getMessage(); 
    3839            $this->fail(); 
    3940        } 
  • branches/1.0/tests/run.php

    r4870 r4889  
    120120$tickets->addTestCase(new Doctrine_Ticket_1304_TestCase()); 
    121121$tickets->addTestCase(new Doctrine_Ticket_1305_TestCase()); 
     122$tickets->addTestCase(new Doctrine_Ticket_1323_TestCase()); 
     123$tickets->addTestCase(new Doctrine_Ticket_1323b2_TestCase()); 
    122124$tickets->addTestCase(new Doctrine_Ticket_1325_TestCase()); 
    123125$tickets->addTestCase(new Doctrine_Ticket_1326_TestCase());