Changeset 4889
- Timestamp:
- 09/08/08 19:48:10 (10 months ago)
- Location:
- branches/1.0
- Files:
-
- 2 added
- 8 modified
-
lib/Doctrine/Collection.php (modified) (2 diffs)
-
lib/Doctrine/Connection/UnitOfWork.php (modified) (1 diff)
-
lib/Doctrine/Relation.php (modified) (1 diff)
-
lib/Doctrine/Relation/Nest.php (modified) (3 diffs)
-
lib/Doctrine/Relation/Parser.php (modified) (5 diffs)
-
tests/Query/LimitTestCase.php (modified) (2 diffs)
-
tests/Relation/ManyToManyTestCase.php (modified) (1 diff)
-
tests/run.php (modified) (1 diff)
-
tests/Ticket/1323b2TestCase.php (added)
-
tests/Ticket/1323TestCase.php (added)
Legend:
- Unmodified
- Added
- Removed
-
branches/1.0/lib/Doctrine/Collection.php
r4720 r4889 264 264 265 265 if ($relation instanceof Doctrine_Relation_ForeignKey || 266 $relation instanceof Doctrine_Relation_LocalKey) { 267 266 $relation instanceof Doctrine_Relation_LocalKey) { 268 267 $this->referenceField = $relation->getForeignFieldName(); 269 268 … … 442 441 if (isset($this->referenceField)) { 443 442 $value = $this->reference->get($this->relation->getLocalFieldName()); 444 445 443 if ($value !== null) { 446 444 $record->set($this->referenceField, $value, false); -
branches/1.0/lib/Doctrine/Connection/UnitOfWork.php
r4886 r4889 445 445 $this->saveGraph($assocRecord); 446 446 } 447 // take snapshot of collection state, so that we know when its modified again 448 $v->takeSnapshot(); 447 449 } 448 450 } -
branches/1.0/lib/Doctrine/Relation.php
r4830 r4889 67 67 'cascade' => array(), // application-level cascades 68 68 'owningSide' => false, // whether this is the owning side 69 'refClassRelation' => null, 69 70 ); 70 71 -
branches/1.0/lib/Doctrine/Relation/Nest.php
r4252 r4889 39 39 * @return string 40 40 */ 41 public function getRelationDql($count, $context = 'record')41 /*public function getRelationDql($count, $context = 'record') 42 42 { 43 43 switch ($context) { … … 73 73 74 74 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 }*/ 102 76 103 77 public function fetchRelatedFor(Doctrine_Record $record) 104 78 { 105 79 $id = $record->getIncremented(); 106 107 80 108 81 if (empty($id) || ! $this->definition['table']->getAttribute(Doctrine::ATTR_LOAD_REFERENCES)) { … … 137 110 ->where(implode(' OR ', $condition)); 138 111 $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); 140 118 141 119 $params = ($this->definition['equal']) ? array($id, $id) : array($id); 120 $res = $q->execute($params); 142 121 143 return $ q->execute($params);122 return $res; 144 123 } 145 124 } -
branches/1.0/lib/Doctrine/Relation/Parser.php
r4586 r4889 156 156 return $this->_relations[$alias]; 157 157 } 158 158 159 159 if (isset($this->_pending[$alias])) { 160 160 $def = $this->_pending[$alias]; 161 161 $identifierColumnNames = $this->_table->getIdentifierColumnNames(); 162 162 $idColumnName = array_pop($identifierColumnNames); 163 163 164 164 // check if reference class name exists 165 165 // if it does we are dealing with association relation … … 167 167 $def = $this->completeAssocDefinition($def); 168 168 $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])) { 172 173 173 174 $parser = $def['refTable']->getRelationParser(); 175 174 176 if ( ! $parser->hasRelation($this->_table->getComponentName())) { 175 177 $parser->bind($this->_table->getComponentName(), … … 181 183 } 182 184 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 } 187 197 } 188 198 } … … 213 223 // unset pending relation 214 224 unset($this->_pending[$alias]); 215 216 225 $this->_relations[$alias] = $rel; 217 226 return $rel; … … 293 302 // foreign key not set 294 303 // try to guess the foreign key 295 296 304 $def['local'] = ($def['foreign'] === $id[0]) ? $id[1] : $id[0]; 297 305 } -
branches/1.0/tests/Query/LimitTestCase.php
r4794 r4889 242 242 243 243 $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]; 245 249 246 250 $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]; 248 256 249 257 $this->assertEqual($user->Group[0]->name, "Action Actors"); 250 258 $this->assertEqual(count($user->Group), 3); 259 $this->assertEqual(count($user2->Group), 3); 260 $this->assertEqual(count($user3->Group), 3); 251 261 252 262 $this->connection->flush(); … … 256 266 257 267 $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 260 270 $users = $q->execute(array($user->Group[1]->id)); 261 271 -
branches/1.0/tests/Relation/ManyToManyTestCase.php
r4109 r4889 36 36 $this->pass(); 37 37 } catch(Doctrine_Exception $e) { 38 echo $e->getMessage(); 38 39 $this->fail(); 39 40 } -
branches/1.0/tests/run.php
r4870 r4889 120 120 $tickets->addTestCase(new Doctrine_Ticket_1304_TestCase()); 121 121 $tickets->addTestCase(new Doctrine_Ticket_1305_TestCase()); 122 $tickets->addTestCase(new Doctrine_Ticket_1323_TestCase()); 123 $tickets->addTestCase(new Doctrine_Ticket_1323b2_TestCase()); 122 124 $tickets->addTestCase(new Doctrine_Ticket_1325_TestCase()); 123 125 $tickets->addTestCase(new Doctrine_Ticket_1326_TestCase());