Changeset 4319
- Timestamp:
- 04/30/08 20:58:42 (14 months ago)
- Location:
- branches/0.11
- Files:
-
- 6 modified
-
lib/Doctrine/Export.php (modified) (2 diffs)
-
lib/Doctrine/Relation.php (modified) (3 diffs)
-
lib/Doctrine/Relation/Parser.php (modified) (3 diffs)
-
lib/Doctrine/Table.php (modified) (2 diffs)
-
manual/docs/en/relations.txt (modified) (1 diff)
-
tests/Ticket/963TestCase.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/0.11/lib/Doctrine/Export.php
r4310 r4319 253 253 254 254 $query = 'CREATE TABLE ' . $this->conn->quoteIdentifier($name, true) . ' (' . $queryFields; 255 255 256 256 $check = $this->getCheckDeclaration($fields); 257 257 … … 261 261 262 262 $query .= ')'; 263 264 265 263 266 264 $sql[] = $query; -
branches/0.11/lib/Doctrine/Relation.php
r4249 r4319 61 61 const MANY = 2; 62 62 63 63 // TRUE => mandatory, everything else is just a default value. this should be refactored 64 // since TRUE can bot be used as a default value this way. All values should be default values. 64 65 protected $definition = array('alias' => true, 65 66 'foreign' => true, … … 77 78 'constraint' => null, 78 79 'equal' => false, 79 'cascade' => array() // application-level cascades 80 'cascade' => array(), // application-level cascades 81 'owningSide' => false // whether this is the owning side 80 82 ); 81 83 … … 140 142 } 141 143 } 142 143 144 $this->definition = $def; 144 145 } -
branches/0.11/lib/Doctrine/Relation/Parser.php
r4300 r4319 114 114 115 115 $this->_pending[$alias] = array_merge($options, array('class' => $name, 'alias' => $alias)); 116 116 117 117 return $this->_pending[$alias]; 118 118 } … … 363 363 364 364 $localIdentifierColumnNames = $this->_table->getIdentifierColumnNames(); 365 $localIdentifierCount = count($localIdentifierColumnNames); 365 366 $localIdColumnName = array_pop($localIdentifierColumnNames); 366 367 $foreignIdentifierColumnNames = $def['table']->getIdentifierColumnNames(); … … 381 382 } 382 383 } else { 383 if (count($localIdentifierColumnNames) > 0 || ($def['local'] !== $localIdColumnName && 384 $def['type'] == Doctrine_Relation::ONE)) { 384 if ($localIdentifierCount == 1) { 385 if ($def['local'] == $localIdColumnName && isset($def['owningSide']) 386 && $def['owningSide'] === true) { 387 $def['localKey'] = true; 388 } else if (($def['local'] !== $localIdColumnName && $def['type'] == Doctrine_Relation::ONE)) { 389 $def['localKey'] = true; 390 } 391 } else if ($localIdentifierCount > 1) { 392 // It's a composite key and since 'foreign' can not point to a composite 393 // key currently, we know that 'local' must be the foreign key. 385 394 $def['localKey'] = true; 386 395 } -
branches/0.11/lib/Doctrine/Table.php
r4301 r4319 594 594 } 595 595 } 596 $options['foreignKeys'] = array(); 597 596 597 $options['foreignKeys'] = isset($this->_options['foreignKeys']) ? 598 $this->_options['foreignKeys'] : array(); 598 599 599 600 if ($parseForeignKeys && $this->getAttribute(Doctrine::ATTR_EXPORT) … … 634 635 } 635 636 } 636 637 637 638 foreach ($constraints as $k => $def) { 638 639 $options['foreignKeys'][$k] = array_merge($options['foreignKeys'][$k], $def); -
branches/0.11/manual/docs/en/relations.txt
r4298 r4319 8 8 second argument is an array consisting of relation options. The option array contains the following keys: 9 9 10 * **local**, the local field of the relation. Local field is the linked field or fields in the defining class. 11 * **foreign**, the foreign field of the relation. Foreign field is the linked field or fields in the linked class. 12 * **refClass**, the name of the reference / join class. This is needed for many-to-many associations. 13 * **onDelete**, the onDelete integrity action. 14 * **onUpdate**, the onUpdate integrity action. 10 * **local**, the local field of the relation. Local field is the linked field in the defining class. 11 * **foreign**, the foreign field of the relation. Foreign field is the linked field in the linked class. 12 * **refClass**, the name of the association class. This is only needed for many-to-many associations. 13 * **owningSide**, (optional) set to boolean true to indicate the owning side of the relation. The owning side is the side that owns the foreign key. There can only be one owning side in an association between two classes. Note that this option is required if Doctrine can't guess the owning side or it's guess is wrong. An example where this is the case is when both 'local' and 'foreign' are part of the identifier (primary key). It never hurts to specify the owning side in this way.', 14 * **onDelete**, (optional) the onDelete integrity action that is applied on the foreign key constraint when the tables are created by Doctrine. 15 * **onUpdate**, (optional) the onUpdate integrity action that is applied on the foreign key constraint when the tables are created by Doctrine. 15 16 16 17 So lets take our first example, say we have two classes Forum_Board and Forum_Thread. Here Forum_Board has many -
branches/0.11/tests/Ticket/963TestCase.php
r4309 r4319 74 74 public function setUp() 75 75 { 76 $this->hasOne('Ticket_963_User as User', array('local' => 'user_id', 76 $this->hasOne('Ticket_963_User as User', array( 77 'local' => 'user_id', 77 78 'foreign' => 'id', 79 'owningSide' => true, 78 80 'onDelete' => 'CASCADE')); 79 81 }