Commit 2d297923 authored by zYne's avatar zYne

Doctrine now works seamlessly in multi-connection environment where...

Doctrine now works seamlessly in multi-connection environment where connections are bound to classes
parent 9aeeffe2
...@@ -243,7 +243,19 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera ...@@ -243,7 +243,19 @@ class Doctrine_Manager extends Doctrine_Configurable implements Countable, Itera
return $this->getConnection($this->bound[$componentName]); return $this->getConnection($this->bound[$componentName]);
return $this->getCurrentConnection(); return $this->getCurrentConnection();
} }
/**
* getTable
* this is the same as Doctrine_Connection::getTable() except
* that it works seamlessly in multi-server/connection environment
*
* @see Doctrine_Connection::getTable()
* @param string $componentName
* @return Doctrine_Table
*/
public function getTable($componentName) {
return $this->getConnectionForComponent($componentName)->getTable($componentName);
}
/** /**
* closes the connection * closes the connection
* *
......
...@@ -1059,6 +1059,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { ...@@ -1059,6 +1059,9 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable {
if($key == 0) { if($key == 0) {
$currPath = substr($currPath,1); $currPath = substr($currPath,1);
$this->conn = Doctrine_Manager::getInstance()
->getConnectionForComponent($name);
$table = $this->conn->getTable($name); $table = $this->conn->getTable($name);
......
...@@ -161,20 +161,20 @@ class Doctrine_RawSql extends Doctrine_Hydrate { ...@@ -161,20 +161,20 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
} }
} }
$q = "SELECT ".implode(', ', $this->parts['select']); $q = 'SELECT '.implode(', ', $this->parts['select']);
$string = $this->applyInheritance(); $string = $this->applyInheritance();
if( ! empty($string)) if( ! empty($string))
$this->parts["where"][] = $string; $this->parts['where'][] = $string;
$copy = $this->parts; $copy = $this->parts;
unset($copy['select']); unset($copy['select']);
$q .= ( ! empty($this->parts['from']))?" FROM ".implode(" ",$this->parts["from"]):''; $q .= ( ! empty($this->parts['from']))? ' FROM ' . implode(' ', $this->parts['from']) : '';
$q .= ( ! empty($this->parts['where']))?" WHERE ".implode(" AND ",$this->parts["where"]):''; $q .= ( ! empty($this->parts['where']))? ' WHERE ' . implode(' AND ', $this->parts['where']) : '';
$q .= ( ! empty($this->parts['groupby']))?" GROUP BY ".implode(", ",$this->parts["groupby"]):''; $q .= ( ! empty($this->parts['groupby']))? ' GROUP BY ' . implode(', ', $this->parts['groupby']) : '';
$q .= ( ! empty($this->parts['having']))?" HAVING ".implode(" ",$this->parts["having"]):''; $q .= ( ! empty($this->parts['having']))? ' HAVING ' . implode(' ', $this->parts['having']) : '';
$q .= ( ! empty($this->parts['orderby']))?" ORDER BY ".implode(" ",$this->parts["orderby"]):''; $q .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(' ', $this->parts['orderby']) : '';
if( ! empty($string)) if( ! empty($string))
array_pop($this->parts['where']); array_pop($this->parts['where']);
...@@ -212,7 +212,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate { ...@@ -212,7 +212,7 @@ class Doctrine_RawSql extends Doctrine_Hydrate {
else else
$alias = $tableAlias; $alias = $tableAlias;
if ($table) { if($table) {
$tableName = $table->getAliasName($component); $tableName = $table->getAliasName($component);
......
...@@ -136,7 +136,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -136,7 +136,9 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
$this->_table = $table; $this->_table = $table;
$exists = ( ! $isNewEntry); $exists = ( ! $isNewEntry);
} else { } else {
$this->_table = Doctrine_Manager::getInstance()->getCurrentConnection()->getTable(get_class($this)); $class = get_class($this);
// get the table of this class
$this->_table = Doctrine_Manager::getInstance()->getConnectionForComponent($class)->getTable(get_class($this));
$exists = false; $exists = false;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment