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
9faf0c5a
Commit
9faf0c5a
authored
Jan 19, 2014
by
Alexander Makarov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Making it IDE-friendly section in AR scopes doc
parent
f21d2ce7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
12 deletions
+37
-12
active-record.md
docs/guide/active-record.md
+37
-12
No files found.
docs/guide/active-record.md
View file @
9faf0c5a
...
...
@@ -625,8 +625,8 @@ $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
like
the following:
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:
```
php
namespace
app\models
;
...
...
@@ -636,10 +636,8 @@ import yii\db\ActiveQuery;
class
CommentQuery
extends
ActiveQuery
{
/**
* Executes query and returns all results as an array.
* @param Connection $db the DB connection used to create the DB command.
* 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.
* @inheritdoc
* @return array|Comment[]
*/
public
function
all
(
$db
=
null
)
{
...
...
@@ -647,12 +645,8 @@ class CommentQuery extends ActiveQuery
}
/**
* Executes query and returns a single row of result.
* @param Connection $db the DB connection used to create the DB command.
* 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.
* @inheritdoc
* @return Comment|array|null
*/
public
function
one
(
$db
=
null
)
{
...
...
@@ -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
------------------------
...
...
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