Sets the WITHIN GROUP ORDER BY part of the query.
public within ( string | array $columns ) | ||
$columns | string | array | the columns (and the directions) to find best row within a group. Columns can be specified in either a string (e.g. "id ASC, name DESC") or an array (e.g. `['id' => Query::SORT_ASC, 'name' => Query::SORT_DESC]`). The method will automatically quote the column names unless a column contains some parenthesis (which means the column contains a DB expression). |
public function testWithin() { $query = new Query(); $query->within('team'); $this->assertEquals(['team' => SORT_ASC], $query->within); $query->addWithin('company'); $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC], $query->within); $query->addWithin('age'); $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_ASC], $query->within); $query->addWithin(['age' => SORT_DESC]); $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_ASC, 'age' => SORT_DESC], $query->within); $query->addWithin('age ASC, company DESC'); $this->assertEquals(['team' => SORT_ASC, 'company' => SORT_DESC, 'age' => SORT_ASC], $query->within); }