1
0
mirror of synced 2025-02-20 14:13:15 +03:00

little enum fix

This commit is contained in:
doctrine 2006-06-21 20:02:40 +00:00
parent d3098e3a25
commit 7b37235fcc
5 changed files with 56 additions and 58 deletions

View File

@ -21,9 +21,9 @@ class Doctrine_Query extends Doctrine_Access {
* @var array $collections an array containing all collections this parser has created/will create
*/
private $collections = array();
private $joined = array();
/**
* @var array $joins an array containing all table joins
*/
private $joins = array();
/**
* @var array $data fetched data
@ -54,20 +54,6 @@ class Doctrine_Query extends Doctrine_Access {
* @var array $tableIndexes
*/
private $tableIndexes = array();
/**
* @var array $dql DQL query string parts
*/
protected $dql = array(
"columns" => array(),
"from" => array(),
"join" => array(),
"where" => array(),
"groupby" => array(),
"having" => array(),
"orderby" => array(),
"limit" => false,
"offset" => false,
);
/**
* @var array $parts SQL query string parts
*/
@ -324,40 +310,7 @@ class Doctrine_Query extends Doctrine_Access {
return $q;
}
/**
* sql delete for mysql
*/
final public function buildDelete() {
if(empty($this->parts["columns"]) || empty($this->parts["from"]))
return false;
$a = array_merge(array_keys($this->parts["from"]),$this->joined);
$q = "DELETE ".implode(", ",$a)." FROM ";
$a = array();
foreach($this->parts["from"] as $tname => $bool) {
$str = $tname;
if(isset($this->parts["join"][$tname]))
$str .= " ".$this->parts["join"][$tname];
$a[] = $str;
}
$q .= implode(", ",$a);
$this->applyInheritance();
if( ! empty($this->parts["where"]))
$q .= " WHERE ".implode(" ",$this->parts["where"]);
if( ! empty($this->parts["orderby"]))
$q .= " ORDER BY ".implode(", ",$this->parts["orderby"]);
if( ! empty($this->parts["limit"]) && ! empty($this->offset))
$q = $this->session->modifyLimitQuery($q,$this->parts["limit"],$this->offset);
return $q;
}
/**
* applyInheritance
* applies column aggregation inheritance to DQL query

View File

@ -30,7 +30,7 @@ class Doctrine_Relation {
/**
* @var Doctrine_Table $table foreign factory
* @var Doctrine_Table $table foreign factory
*/
private $table;
/**
@ -45,20 +45,22 @@ class Doctrine_Relation {
* @var integer $type bind type
*/
private $type;
/**
* @param Doctrine_Table $table
* @param string $local
* @param string $foreign
* @param integer $type
* @param string $alias
*/
public function __construct(Doctrine_Table $table,$local,$foreign,$type) {
public function __construct(Doctrine_Table $table, $local, $foreign, $type) {
$this->table = $table;
$this->local = $local;
$this->foreign = $foreign;
$this->type = $type;
}
/**
* @return integer bind type 1 or 0
* @return integer the relation type, either 0 or 1
*/
public function getType() {
return $this->type;
@ -70,14 +72,14 @@ class Doctrine_Relation {
return $this->table;
}
/**
* @return string the name of the local column
* @return string the name of the local column
*/
public function getLocal() {
return $this->local;
}
/**
* @return string the name of the foreign column where
* the local column is pointing at
* @return string the name of the foreignkey column where
* the localkey column is pointing at
*/
public function getForeign() {
return $this->foreign;

View File

@ -122,7 +122,7 @@ class Doctrine_Validator {
$column = $columns[$key];
if($column[0] == "enum") {
$value = $record->getTable()->enumIndex($value);
$value = $record->getTable()->enumIndex($key, $value);
if($value === false) {
$err[$key] = Doctrine_Validator::ERR_ENUM;

View File

@ -14,6 +14,50 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
$this->dbh->query("DROP TABLE IF EXISTS test_entries");
parent::prepareTables();
}
public function testMultiComponentFetching2() {
$this->session->clear();
$query = new Doctrine_Query($this->session);
$query->from("User.Email, User.Phonenumber");
$users = $query->execute();
$count = count($this->dbh);
$this->assertEqual($users->count(), 8);
$this->assertTrue($users[0]->Email instanceof Email);
$this->assertEqual($users[0]->Phonenumber->count(), 1);
$this->assertEqual($count, count($this->dbh));
}
public function testSelfReferencing() {
$category = new Forum_Category();
$category->name = "Root";
$category->Subcategory[0]->name = "Sub 1";
$category->Subcategory[1]->name = "Sub 2";
$category->Subcategory[0]->Subcategory[0]->name = "Sub 1 Sub 1";
$category->Subcategory[0]->Subcategory[1]->name = "Sub 1 Sub 2";
$category->Subcategory[1]->Subcategory[0]->name = "Sub 2 Sub 1";
$category->Subcategory[1]->Subcategory[1]->name = "Sub 2 Sub 2";
$this->session->flush();
$this->session->clear();
$category = $category->getTable()->find($category->id);
$this->assertEqual($category->name, "Root");
$this->assertEqual($category->Subcategory[0]->name, "Sub 1");
$this->assertEqual($category->Subcategory[1]->name, "Sub 2");
$this->assertEqual($category->Subcategory[0]->Subcategory[0]->name, "Sub 1 Sub 1");
$this->assertEqual($category->Subcategory[0]->Subcategory[1]->name, "Sub 1 Sub 2");
$this->assertEqual($category->Subcategory[1]->Subcategory[0]->name, "Sub 2 Sub 1");
$this->assertEqual($category->Subcategory[1]->Subcategory[1]->name, "Sub 2 Sub 2");
$this->session->clear();
$query = new Doctrine_Query($this->session);
}
public function testHaving() {
$this->session->clear();
@ -973,6 +1017,5 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
//$this->assertTrue(isset($values['max']));
}
}
?>