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
1a3accb6
Commit
1a3accb6
authored
Apr 04, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
removed duplicated joins when using joinWith and via relations
fixes #2650
parent
7437e21d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
17 additions
and
0 deletions
+17
-0
ActiveQuery.php
framework/db/ActiveQuery.php
+8
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+9
-0
No files found.
framework/db/ActiveQuery.php
View file @
1a3accb6
...
...
@@ -414,6 +414,14 @@ class ActiveQuery extends Query implements ActiveQueryInterface
$this
->
with
(
$with
);
}
// remove duplicated joins added by joinWithRelations that may be added
// e.g. when joining a relation and a via relation at the same time
$uniqueJoins
=
[];
foreach
(
$this
->
join
as
$j
)
{
$uniqueJoins
[
serialize
(
$j
)]
=
$j
;
}
$this
->
join
=
array_values
(
$uniqueJoins
);
if
(
!
empty
(
$join
))
{
// append explicit join to joinWith()
// https://github.com/yiisoft/yii2/issues/2880
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
1a3accb6
...
...
@@ -426,7 +426,16 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
1
,
$customers
[
1
]
->
id
);
$this
->
assertTrue
(
$customers
[
0
]
->
isRelationPopulated
(
'orders'
));
$this
->
assertTrue
(
$customers
[
1
]
->
isRelationPopulated
(
'orders'
));
}
/**
* This query will do the same join twice, ensure duplicated JOIN gets removed
* https://github.com/yiisoft/yii2/pull/2650
*/
public
function
testJoinWithVia
()
{
Order
::
getDb
()
->
getQueryBuilder
()
->
separator
=
"
\n
"
;
Order
::
find
()
->
joinWith
(
'itemsInOrder1'
)
->
joinWith
(
'items'
)
->
all
();
}
public
function
testInverseOf
()
...
...
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