From 74af8a28ae8464384e4f10fadc7bae9c2ba37f16 Mon Sep 17 00:00:00 2001 From: guilhermeblanco Date: Thu, 20 Aug 2009 03:21:39 +0000 Subject: [PATCH] [2.0] Removed *where*In methods from QueryBuilder. Finished decouple of QueryBuilder and Expr. Updated docs. --- lib/Doctrine/ORM/QueryBuilder.php | 44 +++++-------------- tests/Doctrine/Tests/ORM/QueryBuilderTest.php | 8 ++-- 2 files changed, 15 insertions(+), 37 deletions(-) diff --git a/lib/Doctrine/ORM/QueryBuilder.php b/lib/Doctrine/ORM/QueryBuilder.php index ee874b475..2f67a1987 100644 --- a/lib/Doctrine/ORM/QueryBuilder.php +++ b/lib/Doctrine/ORM/QueryBuilder.php @@ -27,15 +27,13 @@ use Doctrine\ORM\Query\Expr; * This class is responsible for building DQL query strings via an object oriented * PHP interface. * - * TODO: I don't like the API of using the Expr::*() syntax inside of the QueryBuilder - * methods. What can we do to allow them to do it more fluently with the QueryBuilder. - * - * @author Jonathan H. Wage - * @author Roman Borschel - * @license http://www.opensource.org/licenses/lgpl-license.php LGPL - * @link http://www.doctrine-project.org - * @since 2.0 - * @version $Revision$ + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @link www.doctrine-project.org + * @since 2.0 + * @version $Revision$ + * @author Guilherme Blanco + * @author Jonathan Wage + * @author Roman Borschel */ class QueryBuilder { @@ -313,34 +311,14 @@ class QueryBuilder return $this->add('where', $where); } - public function andWhereIn($expr, $params) - { - return $this->andWhere(Expr::in($expr, $params)); - } - - public function orWhereIn($expr, $params = array()) - { - return $this->orWhere(Expr::in($expr, $params)); - } - - public function andWhereNotIn($expr, $params = array()) - { - return $this->andWhere(Expr::notIn($expr, $params)); - } - - public function orWhereNotIn($expr, $params = array()) - { - return $this->orWhere(Expr::notIn($expr, $params)); - } - public function groupBy($groupBy) { - return $this->add('groupBy', Expr::groupBy($groupBy), false); + return $this->add('groupBy', new Expr\GroupBy(func_get_args())); } public function addGroupBy($groupBy) { - return $this->add('groupBy', Expr::groupBy($groupBy), true); + return $this->add('groupBy', new Expr\GroupBy(func_get_args()), true); } public function having($having) @@ -384,12 +362,12 @@ class QueryBuilder public function orderBy($sort, $order = null) { - return $this->add('orderBy', Expr::orderBy($sort, $order), false); + return $this->add('orderBy', new Expr\OrderBy($sort, $order)); } public function addOrderBy($sort, $order = null) { - return $this->add('orderBy', Expr::orderBy($sort, $order), true); + return $this->add('orderBy', new Expr\OrderBy($sort, $order), true); } /** diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index d5e6e28e9..633f29cc2 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -187,7 +187,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->andWhereIn('u.id', array(1, 2, 3)); + ->andWhere(Expr::in('u.id', array(1, 2, 3))); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id IN(1, 2, 3))'); } @@ -198,7 +198,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->orWhereIn('u.id', array(1, 2, 3)); + ->orWhere(Expr::in('u.id', array(1, 2, 3))); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id IN(1, 2, 3))'); } @@ -209,7 +209,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->andWhereNotIn('u.id', array(1, 2, 3)); + ->andWhere(Expr::notIn('u.id', array(1, 2, 3))); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) AND (u.id NOT IN(1, 2, 3))'); } @@ -220,7 +220,7 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase ->select('u') ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') ->where('u.id = :uid') - ->OrWhereNotIn('u.id', array(1, 2, 3)); + ->OrWhere(Expr::notIn('u.id', array(1, 2, 3))); $this->assertValidQueryBuilder($qb, 'SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE (u.id = :uid) OR (u.id NOT IN(1, 2, 3))'); }