Skip to content
This repository was archived by the owner on May 11, 2021. It is now read-only.

Commit

Permalink
Where does no longer accept array for OR conditions (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek authored May 4, 2021
1 parent 61b17b1 commit d4cc87e
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 61 deletions.
2 changes: 1 addition & 1 deletion phpunit-mssql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-mysql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-oracle.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
2 changes: 1 addition & 1 deletion phpunit-pgsql.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener" />
</listeners>
<coverage processUncoveredFiles="true">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
Expand Down
37 changes: 6 additions & 31 deletions src/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -534,27 +534,10 @@ public function _render_join()
* surrounded by brackets:
* $q->where('user_id',$q->dsql()->table('users')->field('id'));
*
* You can specify OR conditions by passing single argument - array:
* $q->where([
* ['a','is',null],
* ['b','is',null]
* ]);
*
* If entry of the OR condition is not an array, then it's assumed to
* be an expression;
*
* $q->where([
* ['age',20],
* 'age is null'
* ]);
*
* The above use of OR conditions rely on orExpr() functionality. See
* that method for more information.
*
* To specify OR conditions
* To specify OR conditions:
* $q->where($q->orExpr()->where('a',1)->where('b',1));
*
* @param mixed $field Field, array for OR or Expression
* @param mixed $field Field or Expression
* @param mixed $cond Condition such as '=', '>' or 'is not'
* @param mixed $value Value. Will be quoted unless you pass expression
* @param string $kind Do not use directly. Use having()
Expand All @@ -571,17 +554,9 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num
}

// Array as first argument means we have to replace it with orExpr()
if ($num_args === 1 && is_array($field)) {
// or conditions
$or = $this->orExpr();
foreach ($field as $row) {
if (is_array($row)) {
$or->where(...$row);
} else {
$or->where($row);
}
}
$field = $or;
// remove in v2.5
if (is_array($field)) {
throw new Exception('Array input / OR conditions is no longer supported');
}

// first argument is string containing more than just a field name and no more than 2
Expand Down Expand Up @@ -654,7 +629,7 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num
/**
* Same syntax as where().
*
* @param mixed $field Field, array for OR or Expression
* @param mixed $field Field or Expression
* @param string $cond Condition such as '=', '>' or 'is not'
* @param string $value Value. Will be quoted unless you pass expression
*
Expand Down
25 changes: 0 additions & 25 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1339,31 +1339,6 @@ public function testCombinedWhere()
);
}

/**
* Test where() when $field is passed as array. Should create OR conditions.
*
* @covers ::_render_orwhere
* @covers ::_render_where
* @covers ::orExpr
* @covers ::where
*/
public function testOrWhere()
{
$this->assertSame(
'select "name" from "employee" where ("a" = :a or "b" = :b)',
$this->q()
->field('name')->table('employee')->where([['a', 1], ['b', 1]])
->render()
);

$this->assertSame(
'select "name" from "employee" where ("a" = :a or (a=b))',
$this->q()
->field('name')->table('employee')->where([['a', 1], 'a=b'])
->render()
);
}

/**
* Test OrWhere and AndWhere without where condition. Should ignore them.
*
Expand Down

0 comments on commit d4cc87e

Please sign in to comment.