From c929174385b7d7d2afb87ed58df7aee9edb108c1 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 31 Aug 2006 09:04:14 +0000 Subject: [PATCH] Doctrine_Table::getForeignKey -> Doctrine_Table::getRelation --- Doctrine/Collection.php | 4 ++-- Doctrine/Connection.php | 6 +++--- Doctrine/Connection/Mysql.php | 5 ++--- Doctrine/Hydrate.php | 6 +++--- Doctrine/Query.php | 4 ++-- Doctrine/Record.php | 8 ++++---- Doctrine/Session.php | 6 +++--- Doctrine/Table.php | 8 ++++---- Doctrine/Validator.php | 11 +++++++++-- tests/QueryTestCase.php | 4 ++-- tests/RecordTestCase.php | 6 +++--- tests/TableTestCase.php | 6 +++--- 12 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Doctrine/Collection.php b/Doctrine/Collection.php index 7fc28a47b..e6e0536a3 100644 --- a/Doctrine/Collection.php +++ b/Doctrine/Collection.php @@ -540,7 +540,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator return $query; } - $rel = $this->table->getForeignKey($name); + $rel = $this->table->getRelation($name); $table = $rel->getTable(); $foreign = $rel->getForeign(); $local = $rel->getLocal(); @@ -570,7 +570,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator * @return void */ public function populateRelated($name, Doctrine_Collection $coll) { - $rel = $this->table->getForeignKey($name); + $rel = $this->table->getRelation($name); $table = $rel->getTable(); $foreign = $rel->getForeign(); $local = $rel->getLocal(); diff --git a/Doctrine/Connection.php b/Doctrine/Connection.php index 3cec94d42..7ffa0aa9a 100644 --- a/Doctrine/Connection.php +++ b/Doctrine/Connection.php @@ -270,7 +270,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun //print "$k -- adding $nm...
"; } - $rels = $table->getForeignKeys(); + $rels = $table->getRelations(); // group relations @@ -715,7 +715,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun final public function saveRelated(Doctrine_Record $record) { $saveLater = array(); foreach($record->getReferences() as $k=>$v) { - $fk = $record->getTable()->getForeignKey($k); + $fk = $record->getTable()->getRelation($k); if($fk instanceof Doctrine_ForeignKey || $fk instanceof Doctrine_LocalKey) { switch($fk->getType()): @@ -849,7 +849,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @return void */ final public function deleteComposites(Doctrine_Record $record) { - foreach($record->getTable()->getForeignKeys() as $fk) { + foreach($record->getTable()->getRelations() as $fk) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: diff --git a/Doctrine/Connection/Mysql.php b/Doctrine/Connection/Mysql.php index a6d0432c7..89d43e148 100644 --- a/Doctrine/Connection/Mysql.php +++ b/Doctrine/Connection/Mysql.php @@ -13,7 +13,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true); $this->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS); parent::__construct($manager,$pdo); - } + } /** * deletes all data access object from the collection * @param Doctrine_Collection $coll @@ -24,7 +24,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { $a = $coll->getTable()->getCompositePaths(); $a = array_merge(array($coll->getTable()->getComponentName()),$a); - $graph = new Doctrine_DQL_Parser($this); + $graph = new Doctrine_Query(); foreach($coll as $k=>$record) { switch($record->getState()): case Doctrine_Record::STATE_DIRTY: @@ -44,7 +44,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { return $ids; } */ - /** * returns maximum identifier values * diff --git a/Doctrine/Hydrate.php b/Doctrine/Hydrate.php index 9e023da94..34dc5a562 100644 --- a/Doctrine/Hydrate.php +++ b/Doctrine/Hydrate.php @@ -293,7 +293,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $prev[$root] = $coll; - if($this->aggregate) + if($this->aggregate) $return = Doctrine::FETCH_ARRAY; $array = $this->parseData($stmt); @@ -341,7 +341,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $tmp = explode(".", $path); $alias = end($tmp); unset($tmp); - $fk = $this->tables[$pointer]->getForeignKey($alias); + $fk = $this->tables[$pointer]->getRelation($alias); if( ! isset($prev[$pointer]) ) continue; @@ -389,7 +389,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { $tmp = explode(".", $path); $alias = end($tmp); unset($tmp); - $fk = $this->tables[$pointer]->getForeignKey($alias); + $fk = $this->tables[$pointer]->getRelation($alias); $last = $prev[$pointer]->getLast(); switch($fk->getType()): diff --git a/Doctrine/Query.php b/Doctrine/Query.php index 5d8a9f017..c4e13514c 100644 --- a/Doctrine/Query.php +++ b/Doctrine/Query.php @@ -326,7 +326,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $field = $table->getTableName().'.'.$table->getIdentifier(); array_unshift($this->parts['where'], $field.' IN ('.$subquery.')'); $modifyLimit = false; - } + } } $q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):''; @@ -649,7 +649,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $tname = $table->getTableName(); - $fk = $table->getForeignKey($name); + $fk = $table->getRelation($name); $name = $fk->getTable()->getComponentName(); $original = $fk->getTable()->getTableName(); diff --git a/Doctrine/Record.php b/Doctrine/Record.php index 6f5fda19a..3a8cd415b 100644 --- a/Doctrine/Record.php +++ b/Doctrine/Record.php @@ -670,7 +670,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite } else { // if not found, throws InvalidKeyException - $fk = $this->table->getForeignKey($name); + $fk = $this->table->getRelation($name); // one-to-many or one-to-one relation if($fk instanceof Doctrine_ForeignKey || @@ -869,7 +869,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return void */ final public function saveAssociations() { - foreach($this->table->getForeignKeys() as $fk): + foreach($this->table->getRelations() as $fk): $table = $fk->getTable(); $name = $table->getComponentName(); $alias = $this->table->getAlias($name); @@ -1094,7 +1094,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite */ final public function loadReference($name) { - $fk = $this->table->getForeignKey($name); + $fk = $this->table->getRelation($name); $table = $fk->getTable(); $local = $fk->getLocal(); @@ -1267,7 +1267,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * @return integer */ public function countRelated($name) { - $rel = $this->table->getForeignKey($name); + $rel = $this->table->getRelation($name); $componentName = $rel->getTable()->getComponentName(); $alias = $rel->getTable()->getAlias(get_class($this)); $query = new Doctrine_Query(); diff --git a/Doctrine/Session.php b/Doctrine/Session.php index 3f19bf196..7062552d4 100644 --- a/Doctrine/Session.php +++ b/Doctrine/Session.php @@ -270,7 +270,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab //print "$k -- adding $nm...
"; } - $rels = $table->getForeignKeys(); + $rels = $table->getRelations(); // group relations @@ -715,7 +715,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab final public function saveRelated(Doctrine_Record $record) { $saveLater = array(); foreach($record->getReferences() as $k=>$v) { - $fk = $record->getTable()->getForeignKey($k); + $fk = $record->getTable()->getRelation($k); if($fk instanceof Doctrine_ForeignKey || $fk instanceof Doctrine_LocalKey) { switch($fk->getType()): @@ -849,7 +849,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab * @return void */ final public function deleteComposites(Doctrine_Record $record) { - foreach($record->getTable()->getForeignKeys() as $fk) { + foreach($record->getTable()->getRelations() as $fk) { switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: diff --git a/Doctrine/Table.php b/Doctrine/Table.php index a053891d4..856482137 100644 --- a/Doctrine/Table.php +++ b/Doctrine/Table.php @@ -363,7 +363,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { $name = $this->getComponentName(); foreach($this->bound as $k=>$a) { try { - $fk = $this->getForeignKey($k); + $fk = $this->getRelation($k); switch($fk->getType()): case Doctrine_Relation::ONE_COMPOSITE: case Doctrine_Relation::MANY_COMPOSITE: @@ -540,7 +540,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * @param string $name component name of which a foreign key object is bound * @return Doctrine_Relation */ - final public function getForeignKey($name) { + final public function getRelation($name) { $original = $name; if(isset($this->relations[$name])) @@ -624,10 +624,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable { * * @return array */ - final public function getForeignKeys() { + final public function getRelations() { $a = array(); foreach($this->bound as $k=>$v) { - $this->getForeignKey($k); + $this->getRelation($k); } return $this->relations; diff --git a/Doctrine/Validator.php b/Doctrine/Validator.php index 24b83060d..2fd13d814 100644 --- a/Doctrine/Validator.php +++ b/Doctrine/Validator.php @@ -158,14 +158,21 @@ class Doctrine_Validator { $err[$key] = Doctrine_Validator::ERR_LENGTH; continue; } + if( ! is_array($column[2])) + $e = explode("|",$column[2]); + else + $e = $column[2]; - $e = explode("|",$column[2]); foreach($e as $k => $arg) { if(empty($arg) || $arg == "primary" || $arg == "protected" || $arg == "autoincrement") continue; - $args = explode(":",$arg); + if( ! is_integer($k)) { + $args = $arg; + } else + $args = explode(":",$arg); + if( ! isset($args[1])) $args[1] = ''; diff --git a/tests/QueryTestCase.php b/tests/QueryTestCase.php index 08eedc3a8..25baade1e 100644 --- a/tests/QueryTestCase.php +++ b/tests/QueryTestCase.php @@ -874,14 +874,14 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase { $board = new Forum_Board(); $table = $board->getTable(); - $fk = $table->getForeignKey("Threads"); + $fk = $table->getRelation("Threads"); $this->assertEqual($table->getComponentName(), "Forum_Board"); $this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertEqual($fk->getTable()->getComponentName(), "Forum_Thread"); $entry = new Forum_Entry(); - $this->assertTrue($entry->getTable()->getForeignKey("Thread") instanceof Doctrine_LocalKey); + $this->assertTrue($entry->getTable()->getRelation("Thread") instanceof Doctrine_LocalKey); $board->name = "Doctrine Forum"; diff --git a/tests/RecordTestCase.php b/tests/RecordTestCase.php index 57459041d..320f43cee 100644 --- a/tests/RecordTestCase.php +++ b/tests/RecordTestCase.php @@ -369,7 +369,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { public function testTreeStructure() { $e = new Element(); - $fk = $e->getTable()->getForeignKey("Child"); + $fk = $e->getTable()->getRelation("Child"); $this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE); $this->assertEqual($fk->getForeign(), "parent_id"); @@ -438,7 +438,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { $this->assertEqual($e2->message, "user error2"); - $fk = $e->getTable()->getForeignKey("Description"); + $fk = $e->getTable()->getRelation("Description"); $this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertEqual($fk->getLocal(),"file_md5"); $this->assertEqual($fk->getForeign(),"file_md5"); @@ -756,7 +756,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase { // ACCESSING ASSOCIATION OBJECT PROPERTIES $user = new User(); - $this->assertTrue($user->getTable()->getForeignKey("Groupuser") instanceof Doctrine_ForeignKey); + $this->assertTrue($user->getTable()->getRelation("Groupuser") instanceof Doctrine_ForeignKey); $this->assertTrue($user->Groupuser instanceof Doctrine_Collection); $this->assertTrue($user->Groupuser[0] instanceof Groupuser); diff --git a/tests/TableTestCase.php b/tests/TableTestCase.php index c612b6b0d..c22c2945d 100644 --- a/tests/TableTestCase.php +++ b/tests/TableTestCase.php @@ -9,14 +9,14 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase { $table = $this->connection->getTable("User"); } public function testGetForeignKey() { - $fk = $this->objTable->getForeignKey("Group"); + $fk = $this->objTable->getRelation("Group"); $this->assertTrue($fk instanceof Doctrine_Association); $this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE); $this->assertTrue($fk->getLocal() == "user_id"); $this->assertTrue($fk->getForeign() == "group_id"); - $fk = $this->objTable->getForeignKey("Email"); + $fk = $this->objTable->getRelation("Email"); $this->assertTrue($fk instanceof Doctrine_LocalKey); $this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE); @@ -24,7 +24,7 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase { $this->assertTrue($fk->getForeign() == $fk->getTable()->getIdentifier()); - $fk = $this->objTable->getForeignKey("Phonenumber"); + $fk = $this->objTable->getRelation("Phonenumber"); $this->assertTrue($fk instanceof Doctrine_ForeignKey); $this->assertTrue($fk->getTable() instanceof Doctrine_Table); $this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);