Commit ffa3a238 authored by doctrine's avatar doctrine

Preliminary support for many-to-many fetching with column aggregation inheritance

parent c3f186c2
...@@ -41,6 +41,14 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -41,6 +41,14 @@ class Doctrine_Query extends Doctrine_Access {
* @var array $connectors component connectors * @var array $connectors component connectors
*/ */
private $connectors = array(); private $connectors = array();
/**
* @var array $tableAliases
*/
private $tableAliases = array();
/**
* @var array $tableIndexes
*/
private $tableIndexes = array();
/** /**
* @var array $dql DQL query string parts * @var array $dql DQL query string parts
*/ */
...@@ -140,16 +148,18 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -140,16 +148,18 @@ class Doctrine_Query extends Doctrine_Access {
default: default:
throw new Doctrine_Exception("Unknown fetchmode."); throw new Doctrine_Exception("Unknown fetchmode.");
endswitch; endswitch;
$cname = $table->getComponentName();
$this->fetchModes[$cname] = $fetchmode;
$tablename = $table->getTableName();
$component = $table->getComponentName();
$this->fetchModes[$component] = $fetchmode;
$tablename = $this->tableAliases[$component];
$count = count($this->tables); $count = count($this->tables);
foreach($names as $name) { foreach($names as $name) {
if($count == 0) { if($count == 0) {
$this->parts["columns"][] = $tablename.".".$name; $this->parts["columns"][] = $tablename.".".$name;
} else { } else {
$this->parts["columns"][] = $tablename.".".$name." AS ".$cname."__".$name; $this->parts["columns"][] = $tablename.".".$name." AS ".$component."__".$name;
} }
} }
} }
...@@ -317,9 +327,10 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -317,9 +327,10 @@ class Doctrine_Query extends Doctrine_Access {
// get the inheritance maps // get the inheritance maps
$array = array(); $array = array();
foreach($this->tables as $objTable): foreach($this->tables as $table):
$tname = $objTable->getTableName(); $component = $table->getComponentName();
$array[$tname][] = $objTable->getInheritanceMap(); $tableName = $this->tableAliases[$component];
$array[$tableName][] = $table->getInheritanceMap();
endforeach; endforeach;
// apply inheritance maps // apply inheritance maps
...@@ -330,7 +341,7 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -330,7 +341,7 @@ class Doctrine_Query extends Doctrine_Access {
$a = array(); $a = array();
foreach($maps as $map) { foreach($maps as $map) {
$b = array(); $b = array();
foreach($map as $field=>$value) { foreach($map as $field => $value) {
$b[] = $tname.".$field = $value"; $b[] = $tname.".$field = $value";
} }
if( ! empty($b)) $a[] = implode(" AND ",$b); if( ! empty($b)) $a[] = implode(" AND ",$b);
...@@ -390,6 +401,7 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -390,6 +401,7 @@ class Doctrine_Query extends Doctrine_Access {
$keys = array_keys($this->tables); $keys = array_keys($this->tables);
$name = $this->tables[$keys[0]]->getComponentName(); $name = $this->tables[$keys[0]]->getComponentName();
$stmt = $this->session->execute($query,$params); $stmt = $this->session->execute($query,$params);
...@@ -922,6 +934,7 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -922,6 +934,7 @@ class Doctrine_Query extends Doctrine_Access {
$tname = $table->getTableName(); $tname = $table->getTableName();
$this->parts["from"][$tname] = true; $this->parts["from"][$tname] = true;
$this->tableAliases[$name] = $tname;
} else { } else {
$index += strlen($e[($key - 1)]) + 1; $index += strlen($e[($key - 1)]) + 1;
...@@ -961,14 +974,23 @@ class Doctrine_Query extends Doctrine_Access { ...@@ -961,14 +974,23 @@ class Doctrine_Query extends Doctrine_Access {
$assocTableName = $asf->getTableName(); $assocTableName = $asf->getTableName();
$this->parts["join"][$tname][$assocTableName] = $join.$assocTableName." ON ".$tname.".id = ".$assocTableName.".".$fk->getLocal(); $this->parts["join"][$tname][$assocTableName] = $join.$assocTableName." ON ".$tname.".id = ".$assocTableName.".".$fk->getLocal();
$this->parts["join"][$tname][$tname2] = $join.$tname2." ON ".$tname2.".id = ".$assocTableName.".".$fk->getForeign();
if($tname == $tname2) {
$tname2 = $tname."2";
$alias = $tname." AS ".$tname2;
} else
$alias = $tname2;
$this->parts["join"][$tname][$tname2] = $join.$alias." ON ".$tname2.".id = ".$assocTableName.".".$fk->getForeign();
} }
$c = $table->getComponentName(); $c = $table->getComponentName();
$this->joins[$name] = $c; $this->joins[$name] = $c;
$table = $fk->getTable(); $table = $fk->getTable();
$this->tableAliases[$name] = $tname2;
} }
if( ! isset($this->tables[$name])) { if( ! isset($this->tables[$name])) {
......
...@@ -87,7 +87,8 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -87,7 +87,8 @@ class Doctrine_Table extends Doctrine_Configurable {
*/ */
private $boundAliases = array(); private $boundAliases = array();
/** /**
* @var integer $columnCount cached column count * @var integer $columnCount cached column count, Doctrine_Record uses this column count in when
* determining its state
*/ */
private $columnCount; private $columnCount;
...@@ -323,6 +324,18 @@ class Doctrine_Table extends Doctrine_Configurable { ...@@ -323,6 +324,18 @@ class Doctrine_Table extends Doctrine_Configurable {
final public function getSequenceName() { final public function getSequenceName() {
return $this->sequenceName; return $this->sequenceName;
} }
/**
* getParents
*/
final public function getParents() {
return $this->parents;
}
/**
* @return boolean
*/
final public function hasInheritanceMap() {
return (empty($this->inheritanceMap));
}
/** /**
* setInheritanceMap * setInheritanceMap
* @param array $inheritanceMap * @param array $inheritanceMap
......
...@@ -14,7 +14,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -14,7 +14,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->dbh->query("DROP TABLE IF EXISTS test_entries"); $this->dbh->query("DROP TABLE IF EXISTS test_entries");
parent::prepareTables(); parent::prepareTables();
} }
//public function prepareData() { }
public function testManyToManyFetchingWithColumnAggregationInheritance() {
$query = new Doctrine_Query($this->session);
$query->from('User-l:Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 1);
$this->assertEqual($users[0]->Group->count(), 1);
$query->from('User-l.Group-l');
$users = $query->execute();
$this->assertEqual($users->count(), 8);
$this->assertEqual($users[0]->Group->count(), 0);
$this->assertEqual($users[1]->Group->count(), 1);
$this->assertEqual($users[2]->Group->count(), 0);
}
public function testManyToManyFetchingWithColonOperator() { public function testManyToManyFetchingWithColonOperator() {
$query = new Doctrine_Query($this->session); $query = new Doctrine_Query($this->session);
...@@ -90,6 +105,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -90,6 +105,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->assertEqual($tasks[2]->ResourceAlias->count(), 1); $this->assertEqual($tasks[2]->ResourceAlias->count(), 1);
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy); $this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy);
} }
public function testManyToManyFetchingWithDotOperator() { public function testManyToManyFetchingWithDotOperator() {
$query = new Doctrine_Query($this->session); $query = new Doctrine_Query($this->session);
...@@ -847,7 +863,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { ...@@ -847,7 +863,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max'])); //$this->assertTrue(isset($values['max']));
} }
} }
?> ?>
...@@ -44,9 +44,10 @@ $test->addTestCase(new Doctrine_Collection_OffsetTestCase()); ...@@ -44,9 +44,10 @@ $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
$test->addTestCase(new Doctrine_CollectionTestCase()); $test->addTestCase(new Doctrine_CollectionTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
$test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_QueryTestCase());
$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase()); //$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment