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
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Rotua Panjaitan
yii2
Commits
bcf5b464
Commit
bcf5b464
authored
Mar 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2687: ActiveQuery::joinWith() has problem when the query is used twice.
parent
252f49b9
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
11 additions
and
4 deletions
+11
-4
ActiveQuery.php
framework/db/ActiveQuery.php
+4
-4
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+7
-0
No files found.
framework/db/ActiveQuery.php
View file @
bcf5b464
...
...
@@ -236,10 +236,6 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
protected
function
createCommandInternal
(
$db
)
{
if
(
!
empty
(
$this
->
joinWith
))
{
$this
->
buildJoinWith
();
}
/** @var ActiveRecord $modelClass */
$modelClass
=
$this
->
modelClass
;
if
(
$db
===
null
)
{
...
...
@@ -247,6 +243,10 @@ class ActiveQuery extends Query implements ActiveQueryInterface
}
if
(
$this
->
sql
===
null
)
{
if
(
!
empty
(
$this
->
joinWith
))
{
$this
->
buildJoinWith
();
$this
->
joinWith
=
null
;
// clean it up to avoid issue https://github.com/yiisoft/yii2/issues/2687
}
list
(
$sql
,
$params
)
=
$db
->
getQueryBuilder
()
->
build
(
$this
);
}
else
{
$sql
=
$this
->
sql
;
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
bcf5b464
...
...
@@ -393,6 +393,13 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
2
,
count
(
$orders
[
0
]
->
books2
));
$this
->
assertEquals
(
0
,
count
(
$orders
[
1
]
->
books2
));
$this
->
assertEquals
(
1
,
count
(
$orders
[
2
]
->
books2
));
// join with count and query
$query
=
Order
::
find
()
->
joinWith
(
'customer'
);
$count
=
$query
->
count
();
$this
->
assertEquals
(
3
,
$count
);
$orders
=
$query
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
}
public
function
testJoinWithAndScope
()
...
...
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