Preliminary support for many-to-many fetching with column aggregation inheritance
This commit is contained in:
parent
c3f186c2cf
commit
ffa3a23872
@ -41,6 +41,14 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
* @var array $connectors component connectors
|
||||
*/
|
||||
private $connectors = array();
|
||||
/**
|
||||
* @var array $tableAliases
|
||||
*/
|
||||
private $tableAliases = array();
|
||||
/**
|
||||
* @var array $tableIndexes
|
||||
*/
|
||||
private $tableIndexes = array();
|
||||
/**
|
||||
* @var array $dql DQL query string parts
|
||||
*/
|
||||
@ -140,16 +148,18 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
default:
|
||||
throw new Doctrine_Exception("Unknown fetchmode.");
|
||||
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);
|
||||
|
||||
foreach($names as $name) {
|
||||
if($count == 0) {
|
||||
$this->parts["columns"][] = $tablename.".".$name;
|
||||
} 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 {
|
||||
// get the inheritance maps
|
||||
$array = array();
|
||||
|
||||
foreach($this->tables as $objTable):
|
||||
$tname = $objTable->getTableName();
|
||||
$array[$tname][] = $objTable->getInheritanceMap();
|
||||
foreach($this->tables as $table):
|
||||
$component = $table->getComponentName();
|
||||
$tableName = $this->tableAliases[$component];
|
||||
$array[$tableName][] = $table->getInheritanceMap();
|
||||
endforeach;
|
||||
|
||||
// apply inheritance maps
|
||||
@ -330,7 +341,7 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
$a = array();
|
||||
foreach($maps as $map) {
|
||||
$b = array();
|
||||
foreach($map as $field=>$value) {
|
||||
foreach($map as $field => $value) {
|
||||
$b[] = $tname.".$field = $value";
|
||||
}
|
||||
if( ! empty($b)) $a[] = implode(" AND ",$b);
|
||||
@ -390,6 +401,7 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
|
||||
$keys = array_keys($this->tables);
|
||||
|
||||
|
||||
$name = $this->tables[$keys[0]]->getComponentName();
|
||||
$stmt = $this->session->execute($query,$params);
|
||||
|
||||
@ -922,6 +934,7 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
$tname = $table->getTableName();
|
||||
$this->parts["from"][$tname] = true;
|
||||
|
||||
$this->tableAliases[$name] = $tname;
|
||||
} else {
|
||||
|
||||
$index += strlen($e[($key - 1)]) + 1;
|
||||
@ -961,14 +974,23 @@ class Doctrine_Query extends Doctrine_Access {
|
||||
$assocTableName = $asf->getTableName();
|
||||
|
||||
$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();
|
||||
$this->joins[$name] = $c;
|
||||
|
||||
|
||||
$table = $fk->getTable();
|
||||
|
||||
$this->tableAliases[$name] = $tname2;
|
||||
}
|
||||
|
||||
if( ! isset($this->tables[$name])) {
|
||||
|
@ -87,7 +87,8 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
*/
|
||||
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;
|
||||
|
||||
@ -323,6 +324,18 @@ class Doctrine_Table extends Doctrine_Configurable {
|
||||
final public function getSequenceName() {
|
||||
return $this->sequenceName;
|
||||
}
|
||||
/**
|
||||
* getParents
|
||||
*/
|
||||
final public function getParents() {
|
||||
return $this->parents;
|
||||
}
|
||||
/**
|
||||
* @return boolean
|
||||
*/
|
||||
final public function hasInheritanceMap() {
|
||||
return (empty($this->inheritanceMap));
|
||||
}
|
||||
/**
|
||||
* setInheritanceMap
|
||||
* @param array $inheritanceMap
|
||||
|
@ -14,7 +14,22 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
$this->dbh->query("DROP TABLE IF EXISTS test_entries");
|
||||
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() {
|
||||
$query = new Doctrine_Query($this->session);
|
||||
@ -90,6 +105,7 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
$this->assertEqual($tasks[2]->ResourceAlias->count(), 1);
|
||||
$this->assertTrue($tasks[2]->ResourceAlias instanceof Doctrine_Collection_Lazy);
|
||||
}
|
||||
|
||||
public function testManyToManyFetchingWithDotOperator() {
|
||||
$query = new Doctrine_Query($this->session);
|
||||
|
||||
@ -847,7 +863,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
||||
//$this->assertTrue(isset($values['max']));
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
?>
|
||||
|
@ -44,9 +44,10 @@ $test->addTestCase(new Doctrine_Collection_OffsetTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_CollectionTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_QueryTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_PessimisticLockingTestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
Loading…
x
Reference in New Issue
Block a user