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
0b43aa4f
Commit
0b43aa4f
authored
Nov 24, 2013
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixes #1310: ActiveRelation does not preserve order of items on find via() and viaTable()
parent
6920da4a
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
17 deletions
+24
-17
ActiveRelationTrait.php
framework/yii/db/ActiveRelationTrait.php
+24
-17
No files found.
framework/yii/db/ActiveRelationTrait.php
View file @
0b43aa4f
...
@@ -142,35 +142,42 @@ trait ActiveRelationTrait
...
@@ -142,35 +142,42 @@ trait ActiveRelationTrait
*/
*/
private
function
buildBuckets
(
$models
,
$link
,
$viaModels
=
null
,
$viaLink
=
null
)
private
function
buildBuckets
(
$models
,
$link
,
$viaModels
=
null
,
$viaLink
=
null
)
{
{
$buckets
=
[];
$linkKeys
=
array_keys
(
$link
);
foreach
(
$models
as
$i
=>
$model
)
{
$key
=
$this
->
getModelKey
(
$model
,
$linkKeys
);
if
(
$this
->
indexBy
!==
null
)
{
$buckets
[
$key
][
$i
]
=
$model
;
}
else
{
$buckets
[
$key
][]
=
$model
;
}
}
if
(
$viaModels
!==
null
)
{
if
(
$viaModels
!==
null
)
{
$
viaBuckets
=
[];
$
map
=
[];
$viaLinkKeys
=
array_keys
(
$viaLink
);
$viaLinkKeys
=
array_keys
(
$viaLink
);
$linkValues
=
array_values
(
$link
);
$linkValues
=
array_values
(
$link
);
foreach
(
$viaModels
as
$viaModel
)
{
foreach
(
$viaModels
as
$viaModel
)
{
$key1
=
$this
->
getModelKey
(
$viaModel
,
$viaLinkKeys
);
$key1
=
$this
->
getModelKey
(
$viaModel
,
$viaLinkKeys
);
$key2
=
$this
->
getModelKey
(
$viaModel
,
$linkValues
);
$key2
=
$this
->
getModelKey
(
$viaModel
,
$linkValues
);
if
(
isset
(
$buckets
[
$key2
]))
{
$map
[
$key2
][
$key1
]
=
true
;
foreach
(
$buckets
[
$key2
]
as
$i
=>
$bucket
)
{
}
}
$buckets
=
[];
$linkKeys
=
array_keys
(
$link
);
if
(
isset
(
$map
))
{
foreach
(
$models
as
$i
=>
$model
)
{
$key
=
$this
->
getModelKey
(
$model
,
$linkKeys
);
if
(
isset
(
$map
[
$key
]))
{
foreach
(
array_keys
(
$map
[
$key
])
as
$key2
)
{
if
(
$this
->
indexBy
!==
null
)
{
if
(
$this
->
indexBy
!==
null
)
{
$
viaBuckets
[
$key1
][
$i
]
=
$bucket
;
$
buckets
[
$key2
][
$i
]
=
$model
;
}
else
{
}
else
{
$viaBuckets
[
$key1
][]
=
$bucket
;
$buckets
[
$key2
][]
=
$model
;
}
}
}
}
}
}
}
else
{
foreach
(
$models
as
$i
=>
$model
)
{
$key
=
$this
->
getModelKey
(
$model
,
$linkKeys
);
if
(
$this
->
indexBy
!==
null
)
{
$buckets
[
$key
][
$i
]
=
$model
;
}
else
{
$buckets
[
$key
][]
=
$model
;
}
}
}
}
$buckets
=
$viaBuckets
;
}
}
if
(
!
$this
->
multiple
)
{
if
(
!
$this
->
multiple
)
{
...
...
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