Commit a35ef1ce by Carsten Brandt

added andOnCondition and orOnCondition to ActiveQuery

fixes #2957
parent ac12f9ec
...@@ -615,7 +615,46 @@ class ActiveQuery extends Query implements ActiveQueryInterface ...@@ -615,7 +615,46 @@ class ActiveQuery extends Query implements ActiveQueryInterface
{ {
$this->on = $condition; $this->on = $condition;
$this->addParams($params); $this->addParams($params);
return $this;
}
/**
* Adds an additional ON condition to the existing one.
* The new condition and the existing one will be joined using the 'AND' operator.
* @param string|array $condition the new ON condition. Please refer to [[where()]]
* on how to specify this parameter.
* @return static the query object itself
* @see onCondition()
* @see orOnCondition()
*/
public function andOnCondition($condition, $params = [])
{
if ($this->on === null) {
$this->on = $condition;
} else {
$this->on = ['and', $this->on, $condition];
}
$this->addParams($params);
return $this;
}
/**
* Adds an additional ON condition to the existing one.
* The new condition and the existing one will be joined using the 'OR' operator.
* @param string|array $condition the new ON condition. Please refer to [[where()]]
* on how to specify this parameter.
* @return static the query object itself
* @see onCondition()
* @see andOnCondition()
*/
public function orOnCondition($condition, $params = [])
{
if ($this->on === null) {
$this->on = $condition;
} else {
$this->on = ['or', $this->on, $condition];
}
$this->addParams($params);
return $this; return $this;
} }
......
...@@ -30,6 +30,7 @@ trait ActiveQueryTrait ...@@ -30,6 +30,7 @@ trait ActiveQueryTrait
*/ */
public $asArray; public $asArray;
/** /**
* Sets the [[asArray]] property. * Sets the [[asArray]] property.
* @param boolean $value whether to return the query results in terms of arrays instead of Active Records. * @param boolean $value whether to return the query results in terms of arrays instead of Active Records.
...@@ -38,7 +39,6 @@ trait ActiveQueryTrait ...@@ -38,7 +39,6 @@ trait ActiveQueryTrait
public function asArray($value = true) public function asArray($value = true)
{ {
$this->asArray = $value; $this->asArray = $value;
return $this; return $this;
} }
......
...@@ -49,6 +49,7 @@ trait QueryTrait ...@@ -49,6 +49,7 @@ trait QueryTrait
*/ */
public $indexBy; public $indexBy;
/** /**
* Sets the [[indexBy]] property. * Sets the [[indexBy]] property.
* @param string|callable $column the name of the column by which the query results should be indexed by. * @param string|callable $column the name of the column by which the query results should be indexed by.
...@@ -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,7 +84,6 @@ trait QueryTrait ...@@ -84,7 +84,6 @@ trait QueryTrait
public function where($condition) public function where($condition)
{ {
$this->where = $condition; $this->where = $condition;
return $this; return $this;
} }
...@@ -104,7 +103,6 @@ trait QueryTrait ...@@ -104,7 +103,6 @@ trait QueryTrait
} else { } else {
$this->where = ['and', $this->where, $condition]; $this->where = ['and', $this->where, $condition];
} }
return $this; return $this;
} }
...@@ -124,7 +122,6 @@ trait QueryTrait ...@@ -124,7 +122,6 @@ trait QueryTrait
} else { } else {
$this->where = ['or', $this->where, $condition]; $this->where = ['or', $this->where, $condition];
} }
return $this; return $this;
} }
...@@ -144,7 +141,6 @@ trait QueryTrait ...@@ -144,7 +141,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;
} }
...@@ -166,7 +162,6 @@ trait QueryTrait ...@@ -166,7 +162,6 @@ trait QueryTrait
} else { } else {
$this->orderBy = array_merge($this->orderBy, $columns); $this->orderBy = array_merge($this->orderBy, $columns);
} }
return $this; return $this;
} }
...@@ -184,7 +179,6 @@ trait QueryTrait ...@@ -184,7 +179,6 @@ trait QueryTrait
$result[$column] = SORT_ASC; $result[$column] = SORT_ASC;
} }
} }
return $result; return $result;
} }
} }
...@@ -197,7 +191,6 @@ trait QueryTrait ...@@ -197,7 +191,6 @@ trait QueryTrait
public function limit($limit) public function limit($limit)
{ {
$this->limit = $limit; $this->limit = $limit;
return $this; return $this;
} }
...@@ -209,7 +202,6 @@ trait QueryTrait ...@@ -209,7 +202,6 @@ trait QueryTrait
public function offset($offset) public function offset($offset)
{ {
$this->offset = $offset; $this->offset = $offset;
return $this; return $this;
} }
} }
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