Commit 96f1c4c1 by Carsten Brandt

renamed Query::filter() to Query::filterWhere()

parent e5ba8c87
...@@ -400,10 +400,10 @@ class Generator extends \yii\gii\Generator ...@@ -400,10 +400,10 @@ class Generator extends \yii\gii\Generator
case Schema::TYPE_TIME: case Schema::TYPE_TIME:
case Schema::TYPE_DATETIME: case Schema::TYPE_DATETIME:
case Schema::TYPE_TIMESTAMP: case Schema::TYPE_TIMESTAMP:
$conditions[] = "\$query->andFilter(['{$column}' => \$this->{$column}]);"; $conditions[] = "\$query->andFilterWhere(['{$column}' => \$this->{$column}]);";
break; break;
default: default:
$conditions[] = "\$this->addFilter(['like', '{$column}', \$this->{$column}]);"; $conditions[] = "\$this->andFilterWhere(['like', '{$column}', \$this->{$column}]);";
break; break;
} }
} }
......
...@@ -466,7 +466,6 @@ class Query extends Component implements QueryInterface ...@@ -466,7 +466,6 @@ class Query extends Component implements QueryInterface
{ {
$this->where = $condition; $this->where = $condition;
$this->addParams($params); $this->addParams($params);
return $this; return $this;
} }
...@@ -480,13 +479,12 @@ class Query extends Component implements QueryInterface ...@@ -480,13 +479,12 @@ class Query extends Component implements QueryInterface
* @see andFilter() * @see andFilter()
* @see orFilter() * @see orFilter()
*/ */
public function filter($condition, $params = []) public function filterWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->where($condition, $params); $this->where($condition, $params);
} }
return $this; return $this;
} }
...@@ -508,7 +506,6 @@ class Query extends Component implements QueryInterface ...@@ -508,7 +506,6 @@ class Query extends Component implements QueryInterface
$this->where = ['and', $this->where, $condition]; $this->where = ['and', $this->where, $condition];
} }
$this->addParams($params); $this->addParams($params);
return $this; return $this;
} }
...@@ -523,13 +520,12 @@ class Query extends Component implements QueryInterface ...@@ -523,13 +520,12 @@ class Query extends Component implements QueryInterface
* @see filter() * @see filter()
* @see orFilter() * @see orFilter()
*/ */
public function andFilter($condition, $params = []) public function andFilterWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->andWhere($condition, $params); $this->andWhere($condition, $params);
} }
return $this; return $this;
} }
...@@ -551,7 +547,6 @@ class Query extends Component implements QueryInterface ...@@ -551,7 +547,6 @@ class Query extends Component implements QueryInterface
$this->where = ['or', $this->where, $condition]; $this->where = ['or', $this->where, $condition];
} }
$this->addParams($params); $this->addParams($params);
return $this; return $this;
} }
...@@ -566,13 +561,12 @@ class Query extends Component implements QueryInterface ...@@ -566,13 +561,12 @@ class Query extends Component implements QueryInterface
* @see filter() * @see filter()
* @see andFilter() * @see andFilter()
*/ */
public function orFilter($condition, $params = []) public function orFilterWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->orWhere($condition, $params); $this->orWhere($condition, $params);
} }
return $this; return $this;
} }
...@@ -824,7 +818,7 @@ class Query extends Component implements QueryInterface ...@@ -824,7 +818,7 @@ class Query extends Component implements QueryInterface
case 'OR': case 'OR':
for ($i = 1, $operandsCount = count($condition); $i < $operandsCount; $i++) { for ($i = 1, $operandsCount = count($condition); $i < $operandsCount; $i++) {
$subCondition = $this->filterCondition($condition[$i]); $subCondition = $this->filterCondition($condition[$i]);
if ($this->parameterNotEmpty($subCondition)) { if ($this->isParameterNotEmpty($subCondition)) {
$condition[$i] = $subCondition; $condition[$i] = $subCondition;
} else { } else {
unset($condition[$i]); unset($condition[$i]);
...@@ -848,13 +842,13 @@ class Query extends Component implements QueryInterface ...@@ -848,13 +842,13 @@ class Query extends Component implements QueryInterface
case 'OR LIKE': case 'OR LIKE':
case 'NOT LIKE': case 'NOT LIKE':
case 'OR NOT LIKE': case 'OR NOT LIKE':
if (!$this->parameterNotEmpty($condition[2])) { if (!$this->isParameterNotEmpty($condition[2])) {
$condition = []; $condition = [];
} }
break; break;
case 'BETWEEN': case 'BETWEEN':
case 'NOT BETWEEN': case 'NOT BETWEEN':
if (!$this->parameterNotEmpty($condition[2]) && !$this->parameterNotEmpty($condition[3])) { if (!$this->isParameterNotEmpty($condition[2]) && !$this->isParameterNotEmpty($condition[3])) {
$condition = []; $condition = [];
} }
break; break;
......
...@@ -526,92 +526,88 @@ class Query extends Component implements QueryInterface ...@@ -526,92 +526,88 @@ class Query extends Component implements QueryInterface
{ {
$this->where = $condition; $this->where = $condition;
$this->addParams($params); $this->addParams($params);
return $this; return $this;
} }
/** /**
* Sets the WHERE part of the query ignoring empty parameters. * Adds an additional WHERE condition to the existing one.
* * The new condition and the existing one will be joined using the 'AND' operator.
* @param string|array $condition the conditions that should be put in the WHERE part. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query. * @param array $params the parameters (name => value) to be bound to the query.
* @return static the query object itself * @return static the query object itself
* @see andFilter() * @see where()
* @see orFilter() * @see orWhere()
*/ */
public function filter($condition, $params = []) public function andWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); if ($this->where === null) {
if ($condition !== []) { $this->where = $condition;
$this->where($condition, $params); } else {
$this->where = ['and', $this->where, $condition];
} }
$this->addParams($params);
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one. * Adds an additional WHERE condition to the existing one.
* The new condition and the existing one will be joined using the 'AND' operator. * The new condition and the existing one will be joined using the 'OR' operator.
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query. * @param array $params the parameters (name => value) to be bound to the query.
* @return static the query object itself * @return static the query object itself
* @see where() * @see where()
* @see orWhere() * @see andWhere()
*/ */
public function andWhere($condition, $params = []) public function orWhere($condition, $params = [])
{ {
if ($this->where === null) { if ($this->where === null) {
$this->where = $condition; $this->where = $condition;
} else { } else {
$this->where = ['and', $this->where, $condition]; $this->where = ['or', $this->where, $condition];
} }
$this->addParams($params); $this->addParams($params);
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one ignoring empty parameters. * Sets the WHERE part of the query ignoring empty parameters.
* The new condition and the existing one will be joined using the 'AND' operator.
* *
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the conditions that should be put in the WHERE part. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query. * @param array $params the parameters (name => value) to be bound to the query.
* @return static the query object itself * @return static the query object itself
* @see filter() * @see andFilter()
* @see orFilter() * @see orFilter()
*/ */
public function andFilter($condition, $params = []) public function filterWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->andWhere($condition, $params); $this->where($condition, $params);
} }
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one. * Adds an additional WHERE condition to the existing one ignoring empty parameters.
* The new condition and the existing one will be joined using the 'OR' operator. * The new condition and the existing one will be joined using the 'AND' operator.
*
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @param array $params the parameters (name => value) to be bound to the query. * @param array $params the parameters (name => value) to be bound to the query.
* @return static the query object itself * @return static the query object itself
* @see where() * @see filter()
* @see andWhere() * @see orFilter()
*/ */
public function orWhere($condition, $params = []) public function andFilterWhere($condition, $params = [])
{ {
if ($this->where === null) { $condition = $this->filterCondition($condition);
$this->where = $condition; if ($condition !== []) {
} else { $this->andWhere($condition, $params);
$this->where = ['or', $this->where, $condition];
} }
$this->addParams($params);
return $this; return $this;
} }
...@@ -626,13 +622,12 @@ class Query extends Component implements QueryInterface ...@@ -626,13 +622,12 @@ class Query extends Component implements QueryInterface
* @see filter() * @see filter()
* @see andFilter() * @see andFilter()
*/ */
public function orFilter($condition, $params = []) public function orFilterWhere($condition, $params = [])
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->orWhere($condition, $params); $this->orWhere($condition, $params);
} }
return $this; return $this;
} }
...@@ -911,7 +906,7 @@ class Query extends Component implements QueryInterface ...@@ -911,7 +906,7 @@ class Query extends Component implements QueryInterface
case 'OR': case 'OR':
for ($i = 1, $operandsCount = count($condition); $i < $operandsCount; $i++) { for ($i = 1, $operandsCount = count($condition); $i < $operandsCount; $i++) {
$subCondition = $this->filterCondition($condition[$i]); $subCondition = $this->filterCondition($condition[$i]);
if ($this->parameterNotEmpty($subCondition)) { if ($this->isParameterNotEmpty($subCondition)) {
$condition[$i] = $subCondition; $condition[$i] = $subCondition;
} else { } else {
unset($condition[$i]); unset($condition[$i]);
...@@ -935,13 +930,13 @@ class Query extends Component implements QueryInterface ...@@ -935,13 +930,13 @@ class Query extends Component implements QueryInterface
case 'OR LIKE': case 'OR LIKE':
case 'NOT LIKE': case 'NOT LIKE':
case 'OR NOT LIKE': case 'OR NOT LIKE':
if (!$this->parameterNotEmpty($condition[2])) { if (!$this->isParameterNotEmpty($condition[2])) {
$condition = []; $condition = [];
} }
break; break;
case 'BETWEEN': case 'BETWEEN':
case 'NOT BETWEEN': case 'NOT BETWEEN':
if (!$this->parameterNotEmpty($condition[2]) && !$this->parameterNotEmpty($condition[3])) { if (!$this->isParameterNotEmpty($condition[2]) && !$this->isParameterNotEmpty($condition[3])) {
$condition = []; $condition = [];
} }
break; break;
......
...@@ -149,10 +149,10 @@ interface QueryInterface ...@@ -149,10 +149,10 @@ interface QueryInterface
* @param array $condition the conditions that should be put in the WHERE part. Please refer to [[where()]] * @param array $condition the conditions that should be put in the WHERE part. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see andFilter() * @see andFilterWhere()
* @see orFilter() * @see orFilterWhere()
*/ */
public function filter($condition); public function filterWhere($condition);
/** /**
* Adds an additional WHERE condition to the existing one. * Adds an additional WHERE condition to the existing one.
...@@ -171,10 +171,10 @@ interface QueryInterface ...@@ -171,10 +171,10 @@ interface QueryInterface
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see filter() * @see filterWhere()
* @see orFilter() * @see orFilterWhere()
*/ */
public function andFilter($condition); public function andFilterWhere($condition);
/** /**
* Adds an additional WHERE condition to the existing one. * Adds an additional WHERE condition to the existing one.
...@@ -193,10 +193,10 @@ interface QueryInterface ...@@ -193,10 +193,10 @@ interface QueryInterface
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see filter() * @see filterWhere()
* @see andFilter() * @see andFilterWhere()
*/ */
public function orFilter($condition); public function orFilterWhere($condition);
/** /**
* Sets the ORDER BY part of the query. * Sets the ORDER BY part of the query.
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
*/ */
namespace yii\db; namespace yii\db;
use yii\base\NotSupportedException;
/** /**
* The BaseQuery trait represents the minimum method set of a database Query. * The BaseQuery trait represents the minimum method set of a database Query.
...@@ -67,7 +68,6 @@ trait QueryTrait ...@@ -67,7 +68,6 @@ trait QueryTrait
public function indexBy($column) public function indexBy($column)
{ {
$this->indexBy = $column; $this->indexBy = $column;
return $this; return $this;
} }
...@@ -84,149 +84,154 @@ trait QueryTrait ...@@ -84,149 +84,154 @@ trait QueryTrait
public function where($condition) public function where($condition)
{ {
$this->where = $condition; $this->where = $condition;
return $this; return $this;
} }
/** /**
* Returns true if value passed is null, empty string, blank string, or empty array. * Adds an additional WHERE condition to the existing one.
* * The new condition and the existing one will be joined using the 'AND' operator.
* @param $value * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* @return boolean if parameter is empty * on how to specify this parameter.
* @return static the query object itself
* @see where()
* @see orWhere()
*/ */
protected function parameterNotEmpty($value) public function andWhere($condition)
{ {
if (is_string($value)) { if ($this->where === null) {
$value = trim($value); $this->where = $condition;
} else {
$this->where = ['and', $this->where, $condition];
} }
return $value !== '' && $value !== [] && $value !== null; return $this;
} }
/** /**
* Returns new condition with empty (null, empty string, blank string, or empty array) parameters in hash format * Adds an additional WHERE condition to the existing one.
* removed * The new condition and the existing one will be joined using the 'OR' operator.
* * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* @param array $condition original condition * on how to specify this parameter.
* @return array condition with empty parameters removed * @return static the query object itself
* @see where()
* @see andWhere()
*/ */
protected function filterHashCondition($condition) public function orWhere($condition)
{ {
if (is_array($condition) && !isset($condition[0])) { if ($this->where === null) {
// hash format: 'column1' => 'value1', 'column2' => 'value2', ... $this->where = $condition;
$condition = array_filter($condition, [$this, 'parameterNotEmpty']); } else {
} $this->where = ['or', $this->where, $condition];
return $condition;
} }
return $this;
/**
* Returns new condition with empty (null, empty string, blank string, or empty array) parameters removed
*
* @param array $condition original condition
* @return array condition with empty parameters removed
*/
protected function filterCondition($condition)
{
return $this->filterHashCondition($condition);
} }
/** /**
* Sets the WHERE part of the query ignoring empty parameters. * Sets the WHERE part of the query but ignores [[isParameterNotEmpty|empty parameters]].
* *
* See [[QueryInterface::where()]] for detailed documentation. * This function can be used to pass fields of a search form directly as search condition
* by ignoring fields that have not been filled.
* *
* @param array $condition the conditions that should be put in the WHERE part. * @param array $condition the conditions that should be put in the WHERE part.
* See [[where()]] on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see andFilter() * @see where()
* @see orFilter() * @see andFilterWhere()
* @see orFilterWhere()
*/ */
public function filter($condition) public function filterWhere($condition)
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->where($condition); $this->where($condition);
} }
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one. * Adds an additional WHERE condition to the existing one but ignores [[isParameterNotEmpty|empty parameters]].
* The new condition and the existing one will be joined using the 'AND' operator. * The new condition and the existing one will be joined using the 'AND' operator.
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see where() * @see filterWhere()
* @see orWhere() * @see orFilterWhere()
*/ */
public function andWhere($condition) public function andFilterWhere($condition)
{ {
if ($this->where === null) { $condition = $this->filterCondition($condition);
$this->where = $condition; if ($condition !== []) {
} else { $this->andWhere($condition);
$this->where = ['and', $this->where, $condition];
} }
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one ignoring empty parameters. * Adds an additional WHERE condition to the existing one but ignores [[isParameterNotEmpty|empty parameters]].
* The new condition and the existing one will be joined using the 'AND' operator. * The new condition and the existing one will be joined using the 'OR' operator.
*
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param string|array $condition the new WHERE condition. Please refer to [[where()]]
* on how to specify this parameter. * on how to specify this parameter.
* @return static the query object itself * @return static the query object itself
* @see filter() * @see filterWhere()
* @see orFilter() * @see andFilterWhere()
*/ */
public function andFilter($condition) public function orFilterWhere($condition)
{ {
$condition = $this->filterCondition($condition); $condition = $this->filterCondition($condition);
if ($condition !== []) { if ($condition !== []) {
$this->andWhere($condition); $this->orWhere($condition);
} }
return $this; return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one. * Returns a new condition with [[isParameterNotEmpty|empty parameters]] removed.
* The new condition and the existing one will be joined using the 'OR' operator. *
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * @param array $condition original condition
* on how to specify this parameter. * @return array condition with [[isParameterNotEmpty|empty parameters]] removed.
* @return static the query object itself
* @see where()
* @see andWhere()
*/ */
public function orWhere($condition) protected function filterCondition($condition)
{ {
if ($this->where === null) { if (is_array($condition) && !isset($condition[0])) {
$this->where = $condition; return $this->filterHashCondition($condition);
} else { } else {
$this->where = ['or', $this->where, $condition]; throw new NotSupportedException('filterWhere() only supports hash condition format.');
} }
return $this;
} }
/** /**
* Adds an additional WHERE condition to the existing one ignoring empty parameters. * Returns `true` if value passed is not "empty".
* The new condition and the existing one will be joined using the 'OR' operator.
* *
* @param string|array $condition the new WHERE condition. Please refer to [[where()]] * The value is considered "empty", if
* on how to specify this parameter. *
* @return static the query object itself * - it is `null`,
* @see filter() * - an empty string (`''`),
* @see andFilter() * - a string containing only whitespace characters,
* - or an empty array.
*
* @param $value
* @return boolean if parameter is empty
*/ */
public function orFilter($condition) protected function isParameterNotEmpty($value)
{ {
$condition = $this->filterCondition($condition); if (is_string($value)) {
if ($condition !== []) { $value = trim($value);
$this->orWhere($condition); }
return $value !== '' && $value !== [] && $value !== null;
} }
return $this; /**
* Returns a new hash condition without [[isParameterNotEmpty|empty parameters]].
*
* @param array $condition original condition
* @return array condition without [[isParameterNotEmpty|empty parameters]].
*/
protected function filterHashCondition($condition)
{
if (is_array($condition) && !isset($condition[0])) {
// hash format: 'column1' => 'value1', 'column2' => 'value2', ...
return array_filter($condition, [$this, 'isParameterNotEmpty']);
}
return $condition;
} }
/** /**
...@@ -245,7 +250,6 @@ trait QueryTrait ...@@ -245,7 +250,6 @@ trait QueryTrait
public function orderBy($columns) public function orderBy($columns)
{ {
$this->orderBy = $this->normalizeOrderBy($columns); $this->orderBy = $this->normalizeOrderBy($columns);
return $this; return $this;
} }
...@@ -267,7 +271,6 @@ trait QueryTrait ...@@ -267,7 +271,6 @@ trait QueryTrait
} else { } else {
$this->orderBy = array_merge($this->orderBy, $columns); $this->orderBy = array_merge($this->orderBy, $columns);
} }
return $this; return $this;
} }
...@@ -285,7 +288,6 @@ trait QueryTrait ...@@ -285,7 +288,6 @@ trait QueryTrait
$result[$column] = SORT_ASC; $result[$column] = SORT_ASC;
} }
} }
return $result; return $result;
} }
} }
...@@ -298,7 +300,6 @@ trait QueryTrait ...@@ -298,7 +300,6 @@ trait QueryTrait
public function limit($limit) public function limit($limit)
{ {
$this->limit = $limit; $this->limit = $limit;
return $this; return $this;
} }
...@@ -310,7 +311,6 @@ trait QueryTrait ...@@ -310,7 +311,6 @@ trait QueryTrait
public function offset($offset) public function offset($offset)
{ {
$this->offset = $offset; $this->offset = $offset;
return $this; return $this;
} }
} }
...@@ -155,7 +155,7 @@ class QueryTest extends ElasticSearchTestCase ...@@ -155,7 +155,7 @@ class QueryTest extends ElasticSearchTestCase
{ {
// should work with hash format // should work with hash format
$query = new Query; $query = new Query;
$query->filter([ $query->filterWhere([
'id' => 0, 'id' => 0,
'title' => ' ', 'title' => ' ',
'author_ids' => [], 'author_ids' => [],
......
...@@ -72,7 +72,7 @@ class QueryTest extends MongoDbTestCase ...@@ -72,7 +72,7 @@ class QueryTest extends MongoDbTestCase
{ {
// should work with hash format // should work with hash format
$query = new Query; $query = new Query;
$query->filter([ $query->filterWhere([
'id' => 0, 'id' => 0,
'title' => ' ', 'title' => ' ',
'author_ids' => [], 'author_ids' => [],
......
...@@ -64,13 +64,13 @@ class QueryTest extends SphinxTestCase ...@@ -64,13 +64,13 @@ class QueryTest extends SphinxTestCase
{ {
// should just call where() when string is passed // should just call where() when string is passed
$query = new Query; $query = new Query;
$query->filter('id = :id', [':id' => null]); $query->filterWhere('id = :id', [':id' => null]);
$this->assertEquals('id = :id', $query->where); $this->assertEquals('id = :id', $query->where);
$this->assertEquals([':id' => null], $query->params); $this->assertEquals([':id' => null], $query->params);
// should work with hash format // should work with hash format
$query = new Query; $query = new Query;
$query->filter([ $query->filterWhere([
'id' => 0, 'id' => 0,
'title' => ' ', 'title' => ' ',
'author_ids' => [], 'author_ids' => [],
...@@ -86,7 +86,7 @@ class QueryTest extends SphinxTestCase ...@@ -86,7 +86,7 @@ class QueryTest extends SphinxTestCase
// should work with operator format // should work with operator format
$query = new Query; $query = new Query;
$condition = ['like', 'name', 'Alex']; $condition = ['like', 'name', 'Alex'];
$query->filter($condition); $query->filterWhere($condition);
$this->assertEquals($condition, $query->where); $this->assertEquals($condition, $query->where);
$query->andFilter(['between', 'id', null, null]); $query->andFilter(['between', 'id', null, null]);
...@@ -120,7 +120,7 @@ class QueryTest extends SphinxTestCase ...@@ -120,7 +120,7 @@ class QueryTest extends SphinxTestCase
public function testFilterRecursively() public function testFilterRecursively()
{ {
$query = new Query(); $query = new Query();
$query->filter(['and', ['like', 'name', ''], ['like', 'title', ''], ['id' => 1], ['not', ['like', 'name', '']]]); $query->filterWhere(['and', ['like', 'name', ''], ['like', 'title', ''], ['id' => 1], ['not', ['like', 'name', '']]]);
$this->assertEquals(['id' => 1], $query->where); $this->assertEquals(['id' => 1], $query->where);
} }
......
...@@ -53,13 +53,13 @@ class QueryTest extends DatabaseTestCase ...@@ -53,13 +53,13 @@ class QueryTest extends DatabaseTestCase
{ {
// should just call where() when string is passed // should just call where() when string is passed
$query = new Query; $query = new Query;
$query->filter('id = :id', [':id' => null]); $query->filterWhere('id = :id', [':id' => null]);
$this->assertEquals('id = :id', $query->where); $this->assertEquals('id = :id', $query->where);
$this->assertEquals([':id' => null], $query->params); $this->assertEquals([':id' => null], $query->params);
// should work with hash format // should work with hash format
$query = new Query; $query = new Query;
$query->filter([ $query->filterWhere([
'id' => 0, 'id' => 0,
'title' => ' ', 'title' => ' ',
'author_ids' => [], 'author_ids' => [],
...@@ -75,7 +75,7 @@ class QueryTest extends DatabaseTestCase ...@@ -75,7 +75,7 @@ class QueryTest extends DatabaseTestCase
// should work with operator format // should work with operator format
$query = new Query; $query = new Query;
$condition = ['like', 'name', 'Alex']; $condition = ['like', 'name', 'Alex'];
$query->filter($condition); $query->filterWhere($condition);
$this->assertEquals($condition, $query->where); $this->assertEquals($condition, $query->where);
$query->andFilter(['between', 'id', null, null]); $query->andFilter(['between', 'id', null, null]);
...@@ -109,7 +109,7 @@ class QueryTest extends DatabaseTestCase ...@@ -109,7 +109,7 @@ class QueryTest extends DatabaseTestCase
public function testFilterRecursively() public function testFilterRecursively()
{ {
$query = new Query(); $query = new Query();
$query->filter(['and', ['like', 'name', ''], ['like', 'title', ''], ['id' => 1], ['not', ['like', 'name', '']]]); $query->filterWhere(['and', ['like', 'name', ''], ['like', 'title', ''], ['id' => 1], ['not', ['like', 'name', '']]]);
$this->assertEquals(['id' => 1], $query->where); $this->assertEquals(['id' => 1], $query->where);
} }
......
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