Commit 5c19baab by Antonio Ramirez

Merge remote-tracking branch 'upstream/master' into upstream

* upstream/master: Reverted #4098. fix duplicated white space and typo [skip ci] typo fix Fixes #4098: `yii\db\Query::addSelect()` should include `*` when it is called the first time
parents 343e1596 09b00c5c
...@@ -9,7 +9,7 @@ to a `label` property. You could use the following code to achieve this task: ...@@ -9,7 +9,7 @@ to a `label` property. You could use the following code to achieve this task:
$object->label = trim($label); $object->label = trim($label);
``` ```
The drawback of the above code is that you have to call `trim()` everywhere in your code where you met set the `label` The drawback of the above code is that you have to call `trim()` everywhere in your code where you might set the `label`
property. If in the future, the `label` property gets a new requirement, such as the first letter must be captialized, you would again have to modify every bit of code that assigns a value to `label`. The repetition of code leads to bugs and is a practice you want to avoid as much as possible. property. If in the future, the `label` property gets a new requirement, such as the first letter must be captialized, you would again have to modify every bit of code that assigns a value to `label`. The repetition of code leads to bugs and is a practice you want to avoid as much as possible.
To solve this problem, Yii introduces a base class called [[yii\base\Object]] that supports defining properties To solve this problem, Yii introduces a base class called [[yii\base\Object]] that supports defining properties
...@@ -74,4 +74,4 @@ There are several special rules for, and limitations on, the properties defined ...@@ -74,4 +74,4 @@ There are several special rules for, and limitations on, the properties defined
if the defining getter or setter method is public, protected or private. if the defining getter or setter method is public, protected or private.
* The properties can only be defined by *non-static* getters and/or setters. Static methods will not be treated in this same manner. * The properties can only be defined by *non-static* getters and/or setters. Static methods will not be treated in this same manner.
Returning back to the problem described at the beginning of this guide, instead of calling `trim()` everywhere a `label` value is assigned, `trim()` only needs to be invoked within the setter `setLabel()`. And if a new requirement comes that requires the label be initially capitalized, the `setLabel()` method can quickly be modified without touching any other code. The one change will universally affect every assignment to `label`. Returning back to the problem described at the beginning of this guide, instead of calling `trim()` everywhere a `label` value is assigned, `trim()` only needs to be invoked within the setter `setLabel()`. And if a new requirement comes that requires the label be initially capitalized, the `setLabel()` method can quickly be modified without touching any other code. The one change will universally affect every assignment to `label`.
...@@ -24,7 +24,11 @@ class QueryTest extends DatabaseTestCase ...@@ -24,7 +24,11 @@ class QueryTest extends DatabaseTestCase
$this->assertEquals(['id', 'name'], $query->select); $this->assertEquals(['id', 'name'], $query->select);
$this->assertTrue($query->distinct); $this->assertTrue($query->distinct);
$this->assertEquals('something', $query->selectOption); $this->assertEquals('something', $query->selectOption);
$query = new Query();
$query->addSelect('email');
$this->assertEquals(['email'], $query->select);
$query = new Query(); $query = new Query();
$query->select('id, name'); $query->select('id, name');
$query->addSelect('email'); $query->addSelect('email');
......
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