parent
766aec2c94
commit
4408774100
@ -50,7 +50,9 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
* @var array $data fetched data
|
||||
*/
|
||||
protected $data = array();
|
||||
|
||||
/**
|
||||
* @var array $params query input parameters
|
||||
*/
|
||||
protected $params = array();
|
||||
/**
|
||||
* @var Doctrine_Connection $connection Doctrine_Connection object
|
||||
@ -60,13 +62,18 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
* @var Doctrine_View $view Doctrine_View object
|
||||
*/
|
||||
protected $view;
|
||||
|
||||
|
||||
/**
|
||||
* @var boolean $inheritanceApplied
|
||||
*/
|
||||
protected $inheritanceApplied = false;
|
||||
/**
|
||||
* @var boolean $aggregate
|
||||
*/
|
||||
protected $aggregate = false;
|
||||
/**
|
||||
* @var array $compAliases
|
||||
*/
|
||||
protected $compAliases = array();
|
||||
/**
|
||||
* @var array $tableAliases
|
||||
*/
|
||||
@ -100,7 +107,14 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
||||
|
||||
$this->connection = $connection;
|
||||
}
|
||||
/**
|
||||
/**
|
||||
* getComponentAliases
|
||||
*/
|
||||
public function getComponentAliases() {
|
||||
return $this->compAliases;
|
||||
}
|
||||
|
||||
/**
|
||||
* getQuery
|
||||
*
|
||||
* @return string
|
||||
|
@ -663,14 +663,33 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
* @return Doctrine_Table
|
||||
*/
|
||||
final public function load($path, $loadFields = true) {
|
||||
$e = preg_split("/[.:]/",$path);
|
||||
$tmp = explode(' ',$path);
|
||||
$componentAlias = (count($tmp) > 1) ? end($tmp) : false;
|
||||
|
||||
$e = preg_split("/[.:]/", $tmp[0], -1);
|
||||
|
||||
|
||||
if(isset($this->compAliases[$e[0]])) {
|
||||
$end = substr($tmp[0], strlen($e[0]));
|
||||
$path = $this->compAliases[$e[0]] . $end;
|
||||
$e = preg_split("/[.:]/", $path, -1);
|
||||
} else
|
||||
$path = $tmp[0];
|
||||
|
||||
if($componentAlias !== false) {
|
||||
$this->compAliases[$componentAlias] = $path;
|
||||
}
|
||||
|
||||
$index = 0;
|
||||
$currPath = '';
|
||||
$this->tableStack = array();
|
||||
|
||||
foreach($e as $key => $fullname) {
|
||||
try {
|
||||
$copy = $e;
|
||||
|
||||
|
||||
|
||||
$e2 = preg_split("/[-(]/",$fullname);
|
||||
$name = $e2[0];
|
||||
|
||||
@ -679,14 +698,16 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
if($key == 0) {
|
||||
$currPath = substr($currPath,1);
|
||||
|
||||
|
||||
|
||||
$table = $this->connection->getTable($name);
|
||||
|
||||
$tname = $table->getTableName();
|
||||
|
||||
if( ! isset($this->tableAliases[$currPath]))
|
||||
$this->tableIndexes[$tname] = 1;
|
||||
|
||||
$this->parts["from"][$tname] = true;
|
||||
|
||||
$this->parts["from"][$tname] = true;
|
||||
|
||||
$this->tableAliases[$currPath] = $tname;
|
||||
|
||||
@ -864,6 +885,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* parseAggregateValues
|
||||
*/
|
||||
public function parseAggregateValues($fullName, $tableName, array $exploded, $currPath) {
|
||||
$this->aggregate = true;
|
||||
$pos = strpos($fullName,"(");
|
||||
|
@ -6,7 +6,7 @@ class Doctrine_EnumTestCase extends Doctrine_UnitTestCase {
|
||||
parent::prepareTables();
|
||||
}
|
||||
|
||||
public function testSet() {
|
||||
public function testParameterConversion() {
|
||||
$test = new EnumTest();
|
||||
$test->status = 'open';
|
||||
$this->assertEqual($test->status, 'open');
|
||||
|
@ -1,5 +1,54 @@
|
||||
<?php
|
||||
class Doctrine_Query_ComponentAlias_TestCase {
|
||||
class Doctrine_Query_ComponentAlias_TestCase extends Doctrine_UnitTestCase {
|
||||
public function testQueryWithSingleAlias() {
|
||||
$this->connection->clear();
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->from('User u, u.Phonenumber');
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$count = count($this->dbh);
|
||||
|
||||
$this->assertEqual($users->count(), 8);
|
||||
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
|
||||
$this->assertEqual($q->getQuery(),
|
||||
"SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id WHERE (entity.type = 0)");
|
||||
$this->assertEqual($count, count($this->dbh));
|
||||
}
|
||||
|
||||
public function testQueryWithNestedAliases() {
|
||||
$this->connection->clear();
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->from('User u, u.Group g, g.Phonenumber');
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$count = count($this->dbh);
|
||||
|
||||
$this->assertEqual($users->count(), 8);
|
||||
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
|
||||
$this->assertEqual($q->getQuery(),
|
||||
"SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id, entity2.id AS entity2__id, entity2.name AS entity2__name, entity2.loginname AS entity2__loginname, entity2.password AS entity2__password, entity2.type AS entity2__type, entity2.created AS entity2__created, entity2.updated AS entity2__updated, entity2.email_id AS entity2__email_id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id FROM entity LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber ON entity2.id = phonenumber.entity_id WHERE (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
|
||||
|
||||
$this->assertEqual(($count + 1), count($this->dbh));
|
||||
}
|
||||
public function testQueryWithMultipleNestedAliases() {
|
||||
$this->connection->clear();
|
||||
$q = new Doctrine_Query();
|
||||
|
||||
$q->from('User u, u.Phonenumber, u.Group g, g.Phonenumber');
|
||||
|
||||
$users = $q->execute();
|
||||
|
||||
$count = count($this->dbh);
|
||||
|
||||
$this->assertEqual($users->count(), 8);
|
||||
$this->assertTrue($users[0]->Phonenumber instanceof Doctrine_Collection);
|
||||
$this->assertEqual($q->getQuery(),
|
||||
"SELECT entity.id AS entity__id, entity.name AS entity__name, entity.loginname AS entity__loginname, entity.password AS entity__password, entity.type AS entity__type, entity.created AS entity__created, entity.updated AS entity__updated, entity.email_id AS entity__email_id, phonenumber.id AS phonenumber__id, phonenumber.phonenumber AS phonenumber__phonenumber, phonenumber.entity_id AS phonenumber__entity_id, entity2.id AS entity2__id, entity2.name AS entity2__name, entity2.loginname AS entity2__loginname, entity2.password AS entity2__password, entity2.type AS entity2__type, entity2.created AS entity2__created, entity2.updated AS entity2__updated, entity2.email_id AS entity2__email_id, phonenumber2.id AS phonenumber2__id, phonenumber2.phonenumber AS phonenumber2__phonenumber, phonenumber2.entity_id AS phonenumber2__entity_id FROM entity LEFT JOIN phonenumber ON entity.id = phonenumber.entity_id LEFT JOIN groupuser ON entity.id = groupuser.user_id LEFT JOIN entity AS entity2 ON entity2.id = groupuser.group_id LEFT JOIN phonenumber AS phonenumber2 ON entity2.id = phonenumber2.entity_id WHERE (entity.type = 0 AND (entity2.type = 1 OR entity2.type IS NULL))");
|
||||
$this->assertEqual($count, count($this->dbh));
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
@ -31,6 +31,7 @@ require_once("QueryMultiJoinTestCase.php");
|
||||
require_once("QueryReferenceModelTestCase.php");
|
||||
require_once("QueryWhereTestCase.php");
|
||||
require_once("QueryConditionTestCase.php");
|
||||
require_once("QueryComponentAliasTestCase.php");
|
||||
|
||||
require_once("DBTestCase.php");
|
||||
require_once("SchemaTestCase.php");
|
||||
@ -96,12 +97,8 @@ $test->addTestCase(new Doctrine_CollectionTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_ReferenceModel_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EnumTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_DataDict_Sqlite_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_BooleanTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EventListener_Chain_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_RelationAccessTestCase());
|
||||
@ -114,6 +111,12 @@ $test->addTestCase(new Doctrine_Query_Where_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_Condition_TestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_BooleanTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_EnumTestCase());
|
||||
|
||||
$test->addTestCase(new Doctrine_Query_ComponentAlias_TestCase());
|
||||
|
||||
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
|
||||
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user