Changeset 5158 for branches/experimental
- Timestamp:
- 11/06/08 21:26:15 (2 months ago)
- Location:
- branches/experimental/gblanco
- Files:
-
- 5 added
- 7 modified
- 1 copied
-
. (copied) (copied from branches/1.1) (1 prop)
-
lib/Doctrine/Hydrator.php (modified) (2 diffs)
-
lib/Doctrine/Hydrator/RecordDriver.php (modified) (2 diffs)
-
lib/Doctrine/Query.php (modified) (6 diffs)
-
lib/Doctrine/Record.php (modified) (2 diffs)
-
lib/Doctrine/Record/Abstract.php (modified) (1 diff)
-
tests/ClassTableInheritanceTestCase.php (modified) (2 diffs)
-
tests/CTII18nTestCase.php (added)
-
tests/CTITreeStructureTestCase.php (added)
-
tests/models/CTII18nTest.php (added)
-
tests/models/CTITreeLeaf.php (added)
-
tests/NewClassTableInheritanceTestCase.php (added)
-
tests/run.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
branches/experimental/gblanco
-
branches/experimental/gblanco/lib/Doctrine/Hydrator.php
r5073 r5158 335 335 } 336 336 337 if ($cache[$key]['isSimpleType']) { 338 $rowData[$dqlAlias][$fieldName] = $value; 339 } else { 340 $rowData[$dqlAlias][$fieldName] = $table->prepareValue( 341 $fieldName, $value, $cache[$key]['type']); 337 // CTI field assignment 338 $fieldValue = ($cache[$key]['isSimpleType']) ? $value 339 : $table->prepareValue($fieldName, $value, $cache[$key]['type']); 340 341 if (isset($map['joinedParentComponentAlias'])) { 342 $rowData[$map['joinedParentComponentAlias']][$table->getComponentName()][$fieldName] = $fieldValue; 343 } else { 344 $rowData[$dqlAlias][$fieldName] = $fieldValue; 342 345 } 343 346 … … 346 349 // So we know that all aggregate values will always be available in the root component 347 350 if ($agg) { 348 $rowData[$this->_rootAlias][$fieldName] = $ rowData[$dqlAlias][$fieldName];351 $rowData[$this->_rootAlias][$fieldName] = $fieldValue; 349 352 } 350 353 -
branches/experimental/gblanco/lib/Doctrine/Hydrator/RecordDriver.php
r5016 r5158 78 78 public function getElement(array $data, $component) 79 79 { 80 $parentTable = Doctrine::getTable($component); 80 81 $component = $this->_getClassNameToReturn($data, $component); 82 81 83 if ( ! isset($this->_tables[$component])) { 82 84 $this->_tables[$component] = Doctrine::getTable($component); 83 85 $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 86 } 87 88 $componentTable = $this->_tables[$component]; 89 90 foreach($parentTable->getJoinedInheritanceMapChildren() as $child) { 91 if ( 92 isset($data[$child]) && 93 (in_array($child, $componentTable->getOption('joinedParents')) || $child == $componentTable->getComponentName()) 94 ) { 95 $data = array_merge($data, $data[$child]); 96 } 97 98 if (isset($data[$child])) { 99 unset($data[$child]); 100 } 84 101 } 85 102 … … 151 168 $this->_tables[$component]->setAttribute(Doctrine::ATTR_LOAD_REFERENCES, false); 152 169 } 170 171 if (($joinedClasses = $this->_tables[$component]->getOption('joinedInheritanceMap'))) { 172 foreach ($joinedClasses as $class=>$conditions) { 173 list($key, $value) = each($conditions); 174 175 if (isset($data[$key]) && $data[$key] == $value) { 176 return $class; 177 } 178 } 179 } 153 180 154 181 if ( ! ($subclasses = $this->_tables[$component]->getOption('subclasses'))) { -
branches/experimental/gblanco/lib/Doctrine/Query.php
r5126 r5158 494 494 495 495 $fields = $this->_pendingFields[$componentAlias]; 496 $childFields = array(); 496 497 497 498 // check for wildcards 498 499 if (in_array('*', $fields)) { 499 500 $fields = $table->getFieldNames(); 501 502 // CTI fields lookup 503 if ($children = $table->getJoinedInheritanceMapChildren()) { 504 foreach ($children as $child) { 505 $childTable = $this->_conn->getTable($child); 506 $ownedColumns = $childTable->getOwnedColumns(); 507 $childFields[$child] = $ownedColumns; 508 } 509 } 500 510 } else { 501 511 // only auto-add the primary key fields if this query object is not … … 509 519 510 520 $sql = array(); 521 511 522 foreach ($fields as $fieldName) { 512 523 $columnName = $table->getColumnName($fieldName); … … 526 537 . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); 527 538 } 539 } 540 541 // CTI fields inclusion in SQL 542 foreach ($childFields as $childTableName=>$childColumns) { 543 foreach ($childColumns as $fieldName) { 544 $columnName = $table->getColumnName($fieldName); 545 $child = $this->_conn->getTable($childTableName); 546 $columnName = $child->getColumnName($fieldName); 547 $childAlias = $this->getTableAlias($componentAlias . '.' . $child->getComponentName()); 548 $sql[] = $this->_conn->quoteIdentifier($childAlias . '.' . $columnName) 549 . ' AS ' 550 . $this->_conn->quoteIdentifier($childAlias . '__' . $columnName); 551 } 528 552 } 529 553 … … 1790 1814 $this->_tableAliasMap[$tableAlias] = $componentAlias; 1791 1815 1816 $this->_queryComponents[$componentAlias] = array('table' => $table, 'map' => null); 1817 1792 1818 $queryPart .= $this->buildInheritanceJoinSql($name, $componentAlias); 1793 1819 1794 1820 $this->_sqlParts['from'][] = $queryPart; 1795 1796 $this->_queryComponents[$componentAlias] = array('table' => $table, 'map' => null);1797 1821 1798 1822 return $table; … … 1826 1850 $parentTableAlias = $this->getTableAlias($parentAlias, $parentTable->getTableName()); 1827 1851 1828 $queryPart .= ' LEFTJOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName())1852 $queryPart .= ' INNER JOIN ' . $this->_conn->quoteIdentifier($parentTable->getTableName()) 1829 1853 . ' ' . $this->_conn->quoteIdentifier($parentTableAlias) . ' ON '; 1830 1854 … … 1838 1862 . '.' . $this->_conn->quoteIdentifier($column); 1839 1863 } 1864 } 1865 1866 // CTI table relation join building 1867 if ($subchildren = $table->getJoinedInheritanceMapChildren()) { 1868 foreach ($subchildren as $subchild) { 1869 $subchildTable = $this->_conn->getTable($subchild); 1870 $subchildAlias = $componentAlias . '.' . $subchild; 1871 1872 // Get the short alias for the parent table 1873 $subchildTableAlias = $this->getTableAlias($subchildAlias, $subchildTable->getTableName()); 1874 1875 $queryPart .= ' LEFT JOIN ' . $this->_conn->quoteIdentifier($subchildTable->getTableName()) 1876 . ' ' . $this->_conn->quoteIdentifier($subchildTableAlias) . ' ON '; 1877 1878 $this->_queryComponents[$subchildAlias] = array('table' => $subchildTable, 'map' => null, 'joinedParentComponentAlias' => $componentAlias); 1879 1880 //Doctrine::dump($table->getIdentifier()); 1881 foreach ((array) $table->getIdentifier() as $identifier) { 1882 $column = $table->getColumnName($identifier); 1883 1884 $queryPart .= $this->_conn->quoteIdentifier($tableAlias) 1885 . '.' . $this->_conn->quoteIdentifier($column) 1886 . ' = ' . $this->_conn->quoteIdentifier($subchildTableAlias) 1887 . '.' . $this->_conn->quoteIdentifier($column); 1888 } 1889 } 1840 1890 } 1841 1891 -
branches/experimental/gblanco/lib/Doctrine/Record.php
r5098 r5158 1556 1556 if ($this->_data[$field] instanceof Doctrine_Record) { 1557 1557 $a[$field] = $this->_data[$field]->getIncremented(); 1558 1558 1559 if ($a[$field] !== null) { 1559 1560 $this->_data[$field] = $a[$field]; … … 1567 1568 } 1568 1569 */ 1570 } 1571 } 1572 1573 // CTI modified fields inclusion 1574 $map = $this->_table->joinedInheritanceMap; 1575 1576 if ($map != null) { 1577 $map = (isset($map[get_class($this)])) ? $map[get_class($this)] : array(); 1578 } else { 1579 $map = $this->_table->inheritanceMap; 1580 } 1581 1582 foreach ($map as $k => $v) { 1583 $old = $this->get($k, false); 1584 1585 if ((string) $old !== (string) $v || $old === null) { 1586 $a[$k] = $v; 1587 $this->_data[$k] = $v; 1569 1588 } 1570 1589 } -
branches/experimental/gblanco/lib/Doctrine/Record/Abstract.php
r5033 r5158 147 147 } 148 148 149 public function setJoinedInheritanceMap($map) 150 { 151 $this->_table->setOption('joinedInheritanceMap', $map); 152 } 153 149 154 public function setSubclasses($map) 150 155 { -
branches/experimental/gblanco/tests/ClassTableInheritanceTestCase.php
r4211 r5158 112 112 $q->from('CTITest c')->where('c.id = 1'); 113 113 114 $this->assertEqual($q->getSql(), 'SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFTJOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c.id = 1');114 $this->assertEqual($q->getSql(), 'SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c.id = 1'); 115 115 116 116 $record = $q->fetchOne(); … … 128 128 $q->from('CTITest c')->where("c.name = 'Jack'"); 129 129 130 $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFTJOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'");130 $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 131 131 132 132 $q = new Doctrine_Query(); 133 133 $q->from('CTITest c')->where("name = 'Jack'"); 134 134 135 $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c LEFT JOIN c_t_i_test_parent2 c2 ON c.id = c2.id LEFTJOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'");135 $this->assertEqual($q->getSql(), "SELECT c.id AS c__id, c3.added AS c__added, c2.name AS c__name, c2.verified AS c__verified, c.age AS c__age FROM c_t_i_test_parent4 c INNER JOIN c_t_i_test_parent2 c2 ON c.id = c2.id INNER JOIN c_t_i_test_parent3 c3 ON c.id = c3.id WHERE c2.name = 'Jack'"); 136 136 } 137 137 -
branches/experimental/gblanco/tests/run.php
r5122 r5158 258 258 $inheritance->addTestCase(new Doctrine_ColumnAggregationInheritance_TestCase()); 259 259 $inheritance->addTestCase(new Doctrine_ClassTableInheritance_TestCase()); 260 $inheritance->addTestCase(new Doctrine_NewClassTableInheritance_TestCase()); 261 $inheritance->addTestCase(new Doctrine_CTITreeStructure_TestCase()); 262 $inheritance->addTestCase(new Doctrine_CTII18n_TestCase()); 260 263 $inheritance->addTestCase(new Doctrine_Query_ApplyInheritance_TestCase()); 261 264 $test->addTestCase($inheritance);