diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index 0cb917b6b..645761b39 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -47,6 +47,11 @@ class Expr { return new Expr\Select(func_get_args()); } + + public static function from($from, $alias = null) + { + return new Expr\From($from, $alias); + } public static function orderBy($sort = null, $order = null) { @@ -113,7 +118,7 @@ class Expr return new Expr\Func('COUNT', array($x)); } - public static function countDistinct() + public static function countDistinct($x) { return 'COUNT(DISTINCT ' . implode(', ', func_get_args()) . ')'; } @@ -183,14 +188,9 @@ class Expr return new Expr\Func($x . ' NOT IN', (array) $y); } - public static function notEqual($x, $y) - { - return new Expr\Comparison($x, '!=', $y); - } - public static function like($x, $y) { - return new Expr\Math($x, 'LIKE', $y); + return new Expr\Comparison($x, 'LIKE', $y); } public static function concat($x, $y) @@ -232,8 +232,8 @@ class Expr return new Expr\Func('BETWEEN', array($val, $x, $y)); } - public static function trim() + public static function trim($x) { - return new Expr\Func('TRIM', func_get_args()); + return new Expr\Func('TRIM', $x); } } \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Expr/From.php b/lib/Doctrine/ORM/Query/Expr/From.php new file mode 100644 index 000000000..02e6179d5 --- /dev/null +++ b/lib/Doctrine/ORM/Query/Expr/From.php @@ -0,0 +1,48 @@ +. + */ + +namespace Doctrine\ORM\Query\Expr; + +/** + * Expression class for DQL from + * + * @author Jonathan H. Wage + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link http://www.phpdoctrine.org + * @since 2.0 + * @version $Revision$ + */ +class From +{ + private $_from; + private $_alias; + + public function __construct($from, $alias = null) + { + $this->_from = $from; + $this->_alias = $alias; + } + + public function __toString() + { + return $this->_from . ($this->_alias ? ' ' . $this->_alias : ''); + } +} \ No newline at end of file diff --git a/lib/Doctrine/ORM/Query/Expr/Func.php b/lib/Doctrine/ORM/Query/Expr/Func.php index 72bea0e82..55f0a3497 100644 --- a/lib/Doctrine/ORM/Query/Expr/Func.php +++ b/lib/Doctrine/ORM/Query/Expr/Func.php @@ -37,8 +37,8 @@ class Func public function __construct($name, $arguments) { - $this->_name = $name; - $this->_arguments = $arguments; + $this->_name = $name; + $this->_arguments = (array) $arguments; } public function __toString() diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index afcc424e0..efbdfafe9 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -252,9 +252,9 @@ class QueryBuilder return $this->add('set', Expr::eq($key, $value), true); } - public function from($from, $alias) + public function from($from, $alias = null) { - return $this->add('from', $from . ' ' . $alias, true); + return $this->add('from', Expr::from($from, $alias), true); } public function innerJoin($parentAlias, $join, $alias, $condition = null) diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 3ae129ce9..942196c8c 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -140,11 +140,6 @@ class ExprTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('1 = 1', (string) Expr::eq(1, 1)); } - public function testNotEqualExpr() - { - $this->assertEquals('1 != 2', (string) Expr::notEqual(1, 2)); - } - public function testLikeExpr() { $this->assertEquals('a.description LIKE :description', (string) Expr::like('a.description', ':description'));