diff --git a/lib/Doctrine/Query/From.php b/lib/Doctrine/Query/From.php index 41505f524..d6c688bc1 100644 --- a/lib/Doctrine/Query/From.php +++ b/lib/Doctrine/Query/From.php @@ -11,11 +11,32 @@ class Doctrine_Query_From extends Doctrine_Query_Part { * @return void */ final public function parse($str) { - foreach(Doctrine_Query::bracketExplode(trim($str),",", "(",")") as $reference) { - $reference = trim($reference); - $a = explode(".",$reference); - $field = array_pop($a); - $table = $this->query->load($reference); + $str = trim($str); + $parts = Doctrine_Query::bracketExplode($str, 'JOIN'); + + $operator = false; + $last = ''; + + foreach($parts as $k => $part) { + $part = trim($part); + $e = explode(" ", $part); + + if(end($e) == 'INNER' || end($e) == 'LEFT') + $last = array_pop($e); + + $part = implode(" ", $e); + + foreach(Doctrine_Query::bracketExplode($part, ',') as $reference) { + $reference = trim($reference); + $e = explode('.', $reference); + + if($operator) { + $reference = array_shift($e).$operator.implode('.', $e); + } + $table = $this->query->load($reference); + } + + $operator = ($last == 'INNER') ? ':' : '.'; } } diff --git a/tests/run.php b/tests/run.php index 3a8ddfdae..7f2dc0e9d 100644 --- a/tests/run.php +++ b/tests/run.php @@ -33,6 +33,7 @@ require_once("QueryLimitTestCase.php"); require_once("QueryMultiJoinTestCase.php"); require_once("QueryReferenceModelTestCase.php"); require_once("QueryWhereTestCase.php"); +require_once("QueryFromTestCase.php"); require_once("QueryConditionTestCase.php"); require_once("QueryComponentAliasTestCase.php"); require_once("QuerySubqueryTestCase.php"); @@ -126,6 +127,8 @@ $test->addTestCase(new Doctrine_QueryTestCase()); $test->addTestCase(new Doctrine_Query_Where_TestCase()); +$test->addTestCase(new Doctrine_Query_From_TestCase()); + //$test->addTestCase(new Doctrine_Cache_FileTestCase());