Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
28986f98
Commit
28986f98
authored
Jan 19, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed IDE-specific method overrides to @method
parent
9faf0c5a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
50 deletions
+14
-50
active-record.md
docs/guide/active-record.md
+14
-50
No files found.
docs/guide/active-record.md
View file @
28986f98
...
...
@@ -625,67 +625,31 @@ $posts = Post::find()->with([
### 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
object
like the following:
In order to make
most modern IDE autocomplete happy you need to override return types for some methods of both model
and query
like the following:
```
php
namespace
app\models
;
import
yii\db\ActiveQuery
;
class
CommentQuery
extends
ActiveQuery
{
/**
* @inheritdoc
* @return array|Comment[]
*/
public
function
all
(
$db
=
null
)
{
return
parent
::
all
(
$db
);
}
/**
* @inheritdoc
* @return Comment|array|null
/**
* @method \app\models\CommentQuery|static|null find($q = null) static
* @method \app\models\CommentQuery findBySql($sql, $params = []) static
*/
public
function
one
(
$db
=
null
)
{
return
parent
::
one
(
$db
);
}
class
Comment
extends
ActiveRecord
{
// ...
}
```
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
/**
* @method \app\models\Comment|array|null one($db = null)
* @method \app\models\Comment[]|array all($db = null)
*/
public
function
find
(
$q
=
null
)
{
return
parent
::
find
(
$q
);
}
class
CommentQuery
extends
ActiveQuery
{
// ...
}
```
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
------------------------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment