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
78136d42
Commit
78136d42
authored
Mar 26, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #2880: filterByModels() should prefix key columns in a join query.
parent
9b8372d5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
0 deletions
+32
-0
ActiveRelationTrait.php
framework/db/ActiveRelationTrait.php
+27
-0
ActiveRecordTest.php
tests/unit/framework/db/ActiveRecordTest.php
+5
-0
No files found.
framework/db/ActiveRelationTrait.php
View file @
78136d42
...
...
@@ -356,12 +356,39 @@ trait ActiveRelationTrait
return
$buckets
;
}
private
function
prefixKeyColumns
(
$attributes
)
{
if
(
$this
instanceof
ActiveQuery
&&
(
!
empty
(
$this
->
join
)
||
!
empty
(
$this
->
joinWith
)))
{
if
(
empty
(
$this
->
from
))
{
/** @var ActiveRecord $modelClass */
$modelClass
=
$this
->
modelClass
;
$alias
=
$modelClass
::
tableName
();
}
else
{
foreach
(
$this
->
from
as
$alias
=>
$table
)
{
if
(
!
is_string
(
$alias
))
{
$alias
=
$table
;
}
break
;
}
}
if
(
isset
(
$alias
))
{
foreach
(
$attributes
as
$i
=>
$attribute
)
{
$attributes
[
$i
]
=
"
$alias
.
$attribute
"
;
}
}
}
return
$attributes
;
}
/**
* @param array $models
*/
private
function
filterByModels
(
$models
)
{
$attributes
=
array_keys
(
$this
->
link
);
$attributes
=
$this
->
prefixKeyColumns
(
$attributes
);
$values
=
[];
if
(
count
(
$attributes
)
===
1
)
{
// single key
...
...
tests/unit/framework/db/ActiveRecordTest.php
View file @
78136d42
...
...
@@ -402,6 +402,11 @@ class ActiveRecordTest extends DatabaseTestCase
$this
->
assertEquals
(
3
,
$count
);
$orders
=
$query
->
all
();
$this
->
assertEquals
(
3
,
count
(
$orders
));
// https://github.com/yiisoft/yii2/issues/2880
$query
=
Order
::
find
(
1
);
$customer
=
$query
->
getCustomer
()
->
joinWith
(
'orders'
)
->
one
();
$this
->
assertEquals
(
1
,
$customer
->
id
);
}
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