Commit 9faf0c5a by Alexander Makarov

Updated Making it IDE-friendly section in AR scopes doc

parent f21d2ce7
...@@ -625,8 +625,8 @@ $posts = Post::find()->with([ ...@@ -625,8 +625,8 @@ $posts = Post::find()->with([
### Making it IDE-friendly ### Making it IDE-friendly
In order to make your IDE autocomplete happy you can override return types for `one` and `all` methods like In order to make your IDE autocomplete happy you can override return types for `one` and `all` methods of your query
the following: object like the following:
```php ```php
namespace app\models; namespace app\models;
...@@ -636,10 +636,8 @@ import yii\db\ActiveQuery; ...@@ -636,10 +636,8 @@ import yii\db\ActiveQuery;
class CommentQuery extends ActiveQuery class CommentQuery extends ActiveQuery
{ {
/** /**
* Executes query and returns all results as an array. * @inheritdoc
* @param Connection $db the DB connection used to create the DB command. * @return array|Comment[]
* If null, the DB connection returned by [[modelClass]] will be used.
* @return array|Comment[] the query results. If the query results in nothing, an empty array will be returned.
*/ */
public function all($db = null) public function all($db = null)
{ {
...@@ -647,12 +645,8 @@ class CommentQuery extends ActiveQuery ...@@ -647,12 +645,8 @@ class CommentQuery extends ActiveQuery
} }
/** /**
* Executes query and returns a single row of result. * @inheritdoc
* @param Connection $db the DB connection used to create the DB command. * @return Comment|array|null
* If null, the DB connection returned by [[modelClass]] will be used.
* @return Comment|array|null a single row of query result. Depending on the setting of [[asArray]],
* the query result may be either an array or an ActiveRecord object. Null will be returned
* if the query results in nothing.
*/ */
public function one($db = null) public function one($db = null)
{ {
...@@ -661,6 +655,37 @@ class CommentQuery extends ActiveQuery ...@@ -661,6 +655,37 @@ class CommentQuery extends ActiveQuery
} }
``` ```
Then override your model methods:
```php
namespace app\models;
use yii\db\ActiveRecord;
class Comment extends ActiveRecord
{
/**
* @inheritdoc
* @return CustomerQuery
*/
public function findBySQL($sql, $params = [])
{
return parent::findBySQL($sql, $params);
}
/**
* @inheritdoc
* @return null|static|CustomerQuery
*/
public function find($q = null)
{
return parent::find($q);
}
}
```
Note that it can be done via `@method` tag but, unfortunitely [IDE support isn't good enough](http://youtrack.jetbrains.com/issue/WI-17404).
Transactional operations Transactional operations
------------------------ ------------------------
......
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