Doctrine_Table::getForeignKey -> Doctrine_Table::getRelation
This commit is contained in:
parent
14781f1dd3
commit
c929174385
@ -540,7 +540,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rel = $this->table->getForeignKey($name);
|
$rel = $this->table->getRelation($name);
|
||||||
$table = $rel->getTable();
|
$table = $rel->getTable();
|
||||||
$foreign = $rel->getForeign();
|
$foreign = $rel->getForeign();
|
||||||
$local = $rel->getLocal();
|
$local = $rel->getLocal();
|
||||||
@ -570,7 +570,7 @@ class Doctrine_Collection extends Doctrine_Access implements Countable, Iterator
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function populateRelated($name, Doctrine_Collection $coll) {
|
public function populateRelated($name, Doctrine_Collection $coll) {
|
||||||
$rel = $this->table->getForeignKey($name);
|
$rel = $this->table->getRelation($name);
|
||||||
$table = $rel->getTable();
|
$table = $rel->getTable();
|
||||||
$foreign = $rel->getForeign();
|
$foreign = $rel->getForeign();
|
||||||
$local = $rel->getLocal();
|
$local = $rel->getLocal();
|
||||||
|
@ -270,7 +270,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
//print "$k -- adding <b>$nm</b>...<br \>";
|
//print "$k -- adding <b>$nm</b>...<br \>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$rels = $table->getForeignKeys();
|
$rels = $table->getRelations();
|
||||||
|
|
||||||
// group relations
|
// group relations
|
||||||
|
|
||||||
@ -715,7 +715,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
final public function saveRelated(Doctrine_Record $record) {
|
final public function saveRelated(Doctrine_Record $record) {
|
||||||
$saveLater = array();
|
$saveLater = array();
|
||||||
foreach($record->getReferences() as $k=>$v) {
|
foreach($record->getReferences() as $k=>$v) {
|
||||||
$fk = $record->getTable()->getForeignKey($k);
|
$fk = $record->getTable()->getRelation($k);
|
||||||
if($fk instanceof Doctrine_ForeignKey ||
|
if($fk instanceof Doctrine_ForeignKey ||
|
||||||
$fk instanceof Doctrine_LocalKey) {
|
$fk instanceof Doctrine_LocalKey) {
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
@ -849,7 +849,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function deleteComposites(Doctrine_Record $record) {
|
final public function deleteComposites(Doctrine_Record $record) {
|
||||||
foreach($record->getTable()->getForeignKeys() as $fk) {
|
foreach($record->getTable()->getRelations() as $fk) {
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
case Doctrine_Relation::ONE_COMPOSITE:
|
||||||
case Doctrine_Relation::MANY_COMPOSITE:
|
case Doctrine_Relation::MANY_COMPOSITE:
|
||||||
|
@ -13,7 +13,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
$pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);
|
||||||
$this->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
|
$this->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS);
|
||||||
parent::__construct($manager,$pdo);
|
parent::__construct($manager,$pdo);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* deletes all data access object from the collection
|
* deletes all data access object from the collection
|
||||||
* @param Doctrine_Collection $coll
|
* @param Doctrine_Collection $coll
|
||||||
@ -24,7 +24,7 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
$a = $coll->getTable()->getCompositePaths();
|
$a = $coll->getTable()->getCompositePaths();
|
||||||
$a = array_merge(array($coll->getTable()->getComponentName()),$a);
|
$a = array_merge(array($coll->getTable()->getComponentName()),$a);
|
||||||
|
|
||||||
$graph = new Doctrine_DQL_Parser($this);
|
$graph = new Doctrine_Query();
|
||||||
foreach($coll as $k=>$record) {
|
foreach($coll as $k=>$record) {
|
||||||
switch($record->getState()):
|
switch($record->getState()):
|
||||||
case Doctrine_Record::STATE_DIRTY:
|
case Doctrine_Record::STATE_DIRTY:
|
||||||
@ -44,7 +44,6 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common {
|
|||||||
return $ids;
|
return $ids;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns maximum identifier values
|
* returns maximum identifier values
|
||||||
*
|
*
|
||||||
|
@ -293,7 +293,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
$prev[$root] = $coll;
|
$prev[$root] = $coll;
|
||||||
|
|
||||||
|
|
||||||
if($this->aggregate)
|
if($this->aggregate)
|
||||||
$return = Doctrine::FETCH_ARRAY;
|
$return = Doctrine::FETCH_ARRAY;
|
||||||
|
|
||||||
$array = $this->parseData($stmt);
|
$array = $this->parseData($stmt);
|
||||||
@ -341,7 +341,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
$tmp = explode(".", $path);
|
$tmp = explode(".", $path);
|
||||||
$alias = end($tmp);
|
$alias = end($tmp);
|
||||||
unset($tmp);
|
unset($tmp);
|
||||||
$fk = $this->tables[$pointer]->getForeignKey($alias);
|
$fk = $this->tables[$pointer]->getRelation($alias);
|
||||||
|
|
||||||
if( ! isset($prev[$pointer]) )
|
if( ! isset($prev[$pointer]) )
|
||||||
continue;
|
continue;
|
||||||
@ -389,7 +389,7 @@ abstract class Doctrine_Hydrate extends Doctrine_Access {
|
|||||||
$tmp = explode(".", $path);
|
$tmp = explode(".", $path);
|
||||||
$alias = end($tmp);
|
$alias = end($tmp);
|
||||||
unset($tmp);
|
unset($tmp);
|
||||||
$fk = $this->tables[$pointer]->getForeignKey($alias);
|
$fk = $this->tables[$pointer]->getRelation($alias);
|
||||||
$last = $prev[$pointer]->getLast();
|
$last = $prev[$pointer]->getLast();
|
||||||
|
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
|
@ -326,7 +326,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
|
|||||||
$field = $table->getTableName().'.'.$table->getIdentifier();
|
$field = $table->getTableName().'.'.$table->getIdentifier();
|
||||||
array_unshift($this->parts['where'], $field.' IN ('.$subquery.')');
|
array_unshift($this->parts['where'], $field.' IN ('.$subquery.')');
|
||||||
$modifyLimit = false;
|
$modifyLimit = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):'';
|
$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();
|
$tname = $table->getTableName();
|
||||||
|
|
||||||
|
|
||||||
$fk = $table->getForeignKey($name);
|
$fk = $table->getRelation($name);
|
||||||
$name = $fk->getTable()->getComponentName();
|
$name = $fk->getTable()->getComponentName();
|
||||||
$original = $fk->getTable()->getTableName();
|
$original = $fk->getTable()->getTableName();
|
||||||
|
|
||||||
|
@ -670,7 +670,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
} else {
|
} else {
|
||||||
// if not found, throws InvalidKeyException
|
// if not found, throws InvalidKeyException
|
||||||
|
|
||||||
$fk = $this->table->getForeignKey($name);
|
$fk = $this->table->getRelation($name);
|
||||||
|
|
||||||
// one-to-many or one-to-one relation
|
// one-to-many or one-to-one relation
|
||||||
if($fk instanceof Doctrine_ForeignKey ||
|
if($fk instanceof Doctrine_ForeignKey ||
|
||||||
@ -869,7 +869,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function saveAssociations() {
|
final public function saveAssociations() {
|
||||||
foreach($this->table->getForeignKeys() as $fk):
|
foreach($this->table->getRelations() as $fk):
|
||||||
$table = $fk->getTable();
|
$table = $fk->getTable();
|
||||||
$name = $table->getComponentName();
|
$name = $table->getComponentName();
|
||||||
$alias = $this->table->getAlias($name);
|
$alias = $this->table->getAlias($name);
|
||||||
@ -1094,7 +1094,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
*/
|
*/
|
||||||
final public function loadReference($name) {
|
final public function loadReference($name) {
|
||||||
|
|
||||||
$fk = $this->table->getForeignKey($name);
|
$fk = $this->table->getRelation($name);
|
||||||
$table = $fk->getTable();
|
$table = $fk->getTable();
|
||||||
|
|
||||||
$local = $fk->getLocal();
|
$local = $fk->getLocal();
|
||||||
@ -1267,7 +1267,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
|
|||||||
* @return integer
|
* @return integer
|
||||||
*/
|
*/
|
||||||
public function countRelated($name) {
|
public function countRelated($name) {
|
||||||
$rel = $this->table->getForeignKey($name);
|
$rel = $this->table->getRelation($name);
|
||||||
$componentName = $rel->getTable()->getComponentName();
|
$componentName = $rel->getTable()->getComponentName();
|
||||||
$alias = $rel->getTable()->getAlias(get_class($this));
|
$alias = $rel->getTable()->getAlias(get_class($this));
|
||||||
$query = new Doctrine_Query();
|
$query = new Doctrine_Query();
|
||||||
|
@ -270,7 +270,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
|||||||
//print "$k -- adding <b>$nm</b>...<br \>";
|
//print "$k -- adding <b>$nm</b>...<br \>";
|
||||||
}
|
}
|
||||||
|
|
||||||
$rels = $table->getForeignKeys();
|
$rels = $table->getRelations();
|
||||||
|
|
||||||
// group relations
|
// group relations
|
||||||
|
|
||||||
@ -715,7 +715,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
|||||||
final public function saveRelated(Doctrine_Record $record) {
|
final public function saveRelated(Doctrine_Record $record) {
|
||||||
$saveLater = array();
|
$saveLater = array();
|
||||||
foreach($record->getReferences() as $k=>$v) {
|
foreach($record->getReferences() as $k=>$v) {
|
||||||
$fk = $record->getTable()->getForeignKey($k);
|
$fk = $record->getTable()->getRelation($k);
|
||||||
if($fk instanceof Doctrine_ForeignKey ||
|
if($fk instanceof Doctrine_ForeignKey ||
|
||||||
$fk instanceof Doctrine_LocalKey) {
|
$fk instanceof Doctrine_LocalKey) {
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
@ -849,7 +849,7 @@ abstract class Doctrine_Session extends Doctrine_Configurable implements Countab
|
|||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
final public function deleteComposites(Doctrine_Record $record) {
|
final public function deleteComposites(Doctrine_Record $record) {
|
||||||
foreach($record->getTable()->getForeignKeys() as $fk) {
|
foreach($record->getTable()->getRelations() as $fk) {
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
case Doctrine_Relation::ONE_COMPOSITE:
|
||||||
case Doctrine_Relation::MANY_COMPOSITE:
|
case Doctrine_Relation::MANY_COMPOSITE:
|
||||||
|
@ -363,7 +363,7 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
$name = $this->getComponentName();
|
$name = $this->getComponentName();
|
||||||
foreach($this->bound as $k=>$a) {
|
foreach($this->bound as $k=>$a) {
|
||||||
try {
|
try {
|
||||||
$fk = $this->getForeignKey($k);
|
$fk = $this->getRelation($k);
|
||||||
switch($fk->getType()):
|
switch($fk->getType()):
|
||||||
case Doctrine_Relation::ONE_COMPOSITE:
|
case Doctrine_Relation::ONE_COMPOSITE:
|
||||||
case Doctrine_Relation::MANY_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
|
* @param string $name component name of which a foreign key object is bound
|
||||||
* @return Doctrine_Relation
|
* @return Doctrine_Relation
|
||||||
*/
|
*/
|
||||||
final public function getForeignKey($name) {
|
final public function getRelation($name) {
|
||||||
$original = $name;
|
$original = $name;
|
||||||
|
|
||||||
if(isset($this->relations[$name]))
|
if(isset($this->relations[$name]))
|
||||||
@ -624,10 +624,10 @@ class Doctrine_Table extends Doctrine_Configurable implements Countable {
|
|||||||
*
|
*
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
final public function getForeignKeys() {
|
final public function getRelations() {
|
||||||
$a = array();
|
$a = array();
|
||||||
foreach($this->bound as $k=>$v) {
|
foreach($this->bound as $k=>$v) {
|
||||||
$this->getForeignKey($k);
|
$this->getRelation($k);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->relations;
|
return $this->relations;
|
||||||
|
@ -158,14 +158,21 @@ class Doctrine_Validator {
|
|||||||
$err[$key] = Doctrine_Validator::ERR_LENGTH;
|
$err[$key] = Doctrine_Validator::ERR_LENGTH;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if( ! is_array($column[2]))
|
||||||
|
$e = explode("|",$column[2]);
|
||||||
|
else
|
||||||
|
$e = $column[2];
|
||||||
|
|
||||||
$e = explode("|",$column[2]);
|
|
||||||
|
|
||||||
foreach($e as $k => $arg) {
|
foreach($e as $k => $arg) {
|
||||||
if(empty($arg) || $arg == "primary" || $arg == "protected" || $arg == "autoincrement")
|
if(empty($arg) || $arg == "primary" || $arg == "protected" || $arg == "autoincrement")
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
$args = explode(":",$arg);
|
if( ! is_integer($k)) {
|
||||||
|
$args = $arg;
|
||||||
|
} else
|
||||||
|
$args = explode(":",$arg);
|
||||||
|
|
||||||
if( ! isset($args[1]))
|
if( ! isset($args[1]))
|
||||||
$args[1] = '';
|
$args[1] = '';
|
||||||
|
|
||||||
|
@ -874,14 +874,14 @@ class Doctrine_QueryTestCase extends Doctrine_UnitTestCase {
|
|||||||
|
|
||||||
$board = new Forum_Board();
|
$board = new Forum_Board();
|
||||||
$table = $board->getTable();
|
$table = $board->getTable();
|
||||||
$fk = $table->getForeignKey("Threads");
|
$fk = $table->getRelation("Threads");
|
||||||
|
|
||||||
$this->assertEqual($table->getComponentName(), "Forum_Board");
|
$this->assertEqual($table->getComponentName(), "Forum_Board");
|
||||||
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
||||||
$this->assertEqual($fk->getTable()->getComponentName(), "Forum_Thread");
|
$this->assertEqual($fk->getTable()->getComponentName(), "Forum_Thread");
|
||||||
|
|
||||||
$entry = new Forum_Entry();
|
$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";
|
$board->name = "Doctrine Forum";
|
||||||
|
|
||||||
|
@ -369,7 +369,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
|||||||
public function testTreeStructure() {
|
public function testTreeStructure() {
|
||||||
$e = new Element();
|
$e = new Element();
|
||||||
|
|
||||||
$fk = $e->getTable()->getForeignKey("Child");
|
$fk = $e->getTable()->getRelation("Child");
|
||||||
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
||||||
$this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE);
|
$this->assertEqual($fk->getType(), Doctrine_Relation::MANY_AGGREGATE);
|
||||||
$this->assertEqual($fk->getForeign(), "parent_id");
|
$this->assertEqual($fk->getForeign(), "parent_id");
|
||||||
@ -438,7 +438,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
|||||||
$this->assertEqual($e2->message, "user error2");
|
$this->assertEqual($e2->message, "user error2");
|
||||||
|
|
||||||
|
|
||||||
$fk = $e->getTable()->getForeignKey("Description");
|
$fk = $e->getTable()->getRelation("Description");
|
||||||
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
$this->assertTrue($fk instanceof Doctrine_ForeignKey);
|
||||||
$this->assertEqual($fk->getLocal(),"file_md5");
|
$this->assertEqual($fk->getLocal(),"file_md5");
|
||||||
$this->assertEqual($fk->getForeign(),"file_md5");
|
$this->assertEqual($fk->getForeign(),"file_md5");
|
||||||
@ -756,7 +756,7 @@ class Doctrine_RecordTestCase extends Doctrine_UnitTestCase {
|
|||||||
// ACCESSING ASSOCIATION OBJECT PROPERTIES
|
// ACCESSING ASSOCIATION OBJECT PROPERTIES
|
||||||
|
|
||||||
$user = new User();
|
$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 instanceof Doctrine_Collection);
|
||||||
$this->assertTrue($user->Groupuser[0] instanceof Groupuser);
|
$this->assertTrue($user->Groupuser[0] instanceof Groupuser);
|
||||||
|
|
||||||
|
@ -9,14 +9,14 @@ class Doctrine_TableTestCase extends Doctrine_UnitTestCase {
|
|||||||
$table = $this->connection->getTable("User");
|
$table = $this->connection->getTable("User");
|
||||||
}
|
}
|
||||||
public function testGetForeignKey() {
|
public function testGetForeignKey() {
|
||||||
$fk = $this->objTable->getForeignKey("Group");
|
$fk = $this->objTable->getRelation("Group");
|
||||||
$this->assertTrue($fk instanceof Doctrine_Association);
|
$this->assertTrue($fk instanceof Doctrine_Association);
|
||||||
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
||||||
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
|
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_AGGREGATE);
|
||||||
$this->assertTrue($fk->getLocal() == "user_id");
|
$this->assertTrue($fk->getLocal() == "user_id");
|
||||||
$this->assertTrue($fk->getForeign() == "group_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 instanceof Doctrine_LocalKey);
|
||||||
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
||||||
$this->assertTrue($fk->getType() == Doctrine_Relation::ONE_COMPOSITE);
|
$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());
|
$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 instanceof Doctrine_ForeignKey);
|
||||||
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
$this->assertTrue($fk->getTable() instanceof Doctrine_Table);
|
||||||
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);
|
$this->assertTrue($fk->getType() == Doctrine_Relation::MANY_COMPOSITE);
|
||||||
|
Loading…
Reference in New Issue
Block a user