Commit 28986f98 by Alexander Makarov

Changed IDE-specific method overrides to @method

parent 9faf0c5a
...@@ -625,67 +625,31 @@ $posts = Post::find()->with([ ...@@ -625,67 +625,31 @@ $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 of your query In order to make most modern IDE autocomplete happy you need to override return types for some methods of both model
object like the following: and query like the following:
```php ```php
namespace app\models; /**
* @method \app\models\CommentQuery|static|null find($q = null) static
import yii\db\ActiveQuery; * @method \app\models\CommentQuery findBySql($sql, $params = []) static
class CommentQuery extends ActiveQuery
{
/**
* @inheritdoc
* @return array|Comment[]
*/
public function all($db = null)
{
return parent::all($db);
}
/**
* @inheritdoc
* @return Comment|array|null
*/ */
public function one($db = null) class Comment extends ActiveRecord
{ {
return parent::one($db); // ...
}
} }
``` ```
Then override your model methods:
```php ```php
namespace app\models; /**
* @method \app\models\Comment|array|null one($db = null)
use yii\db\ActiveRecord; * @method \app\models\Comment[]|array all($db = null)
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) class CommentQuery extends ActiveQuery
{ {
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