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
c3216bd0
Commit
c3216bd0
authored
Mar 10, 2012
by
Qiang Xue
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
renamed indexBy to be index.
parent
769a114d
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
15 additions
and
15 deletions
+15
-15
ActiveFinder.php
framework/db/ar/ActiveFinder.php
+6
-6
ActiveRecord.php
framework/db/ar/ActiveRecord.php
+2
-2
BaseActiveQuery.php
framework/db/ar/BaseActiveQuery.php
+3
-3
JoinElement.php
framework/db/ar/JoinElement.php
+2
-2
ActiveRecordTest.php
tests/unit/framework/db/ar/ActiveRecordTest.php
+2
-2
No files found.
framework/db/ar/ActiveFinder.php
View file @
c3216bd0
...
@@ -74,21 +74,21 @@ class ActiveFinder extends \yii\base\Object
...
@@ -74,21 +74,21 @@ class ActiveFinder extends \yii\base\Object
$rows
=
$command
->
queryAll
();
$rows
=
$command
->
queryAll
();
$records
=
array
();
$records
=
array
();
if
(
$query
->
asArray
)
{
if
(
$query
->
asArray
)
{
if
(
$query
->
index
By
===
null
)
{
if
(
$query
->
index
===
null
)
{
return
$rows
;
return
$rows
;
}
}
foreach
(
$rows
as
$row
)
{
foreach
(
$rows
as
$row
)
{
$records
[
$row
[
$query
->
index
By
]]
=
$row
;
$records
[
$row
[
$query
->
index
]]
=
$row
;
}
}
}
else
{
}
else
{
$class
=
$query
->
modelClass
;
$class
=
$query
->
modelClass
;
if
(
$query
->
index
By
===
null
)
{
if
(
$query
->
index
===
null
)
{
foreach
(
$rows
as
$row
)
{
foreach
(
$rows
as
$row
)
{
$records
[]
=
$class
::
create
(
$row
);
$records
[]
=
$class
::
create
(
$row
);
}
}
}
else
{
}
else
{
foreach
(
$rows
as
$row
)
{
foreach
(
$rows
as
$row
)
{
$records
[
$row
[
$query
->
index
By
]]
=
$class
::
create
(
$row
);
$records
[
$row
[
$query
->
index
]]
=
$class
::
create
(
$row
);
}
}
}
}
}
}
...
@@ -125,10 +125,10 @@ class ActiveFinder extends \yii\base\Object
...
@@ -125,10 +125,10 @@ class ActiveFinder extends \yii\base\Object
$joinTree
->
createRecord
(
$row
);
$joinTree
->
createRecord
(
$row
);
}
}
if
(
$query
->
index
By
!==
null
)
{
if
(
$query
->
index
!==
null
)
{
$records
=
array
();
$records
=
array
();
foreach
(
$joinTree
->
records
as
$record
)
{
foreach
(
$joinTree
->
records
as
$record
)
{
$records
[
$record
[
$query
->
index
By
]]
=
$record
;
$records
[
$record
[
$query
->
index
]]
=
$record
;
}
}
return
$records
;
return
$records
;
}
else
{
}
else
{
...
...
framework/db/ar/ActiveRecord.php
View file @
c3216bd0
...
@@ -524,8 +524,8 @@ abstract class ActiveRecord extends Model
...
@@ -524,8 +524,8 @@ abstract class ActiveRecord extends Model
public
function
addRelatedRecord
(
$relation
,
$record
)
public
function
addRelatedRecord
(
$relation
,
$record
)
{
{
if
(
$relation
->
hasMany
)
{
if
(
$relation
->
hasMany
)
{
if
(
$relation
->
index
By
!==
null
)
{
if
(
$relation
->
index
!==
null
)
{
$this
->
_related
[
$relation
->
name
][
$record
->
{
$relation
->
index
By
}]
=
$record
;
$this
->
_related
[
$relation
->
name
][
$record
->
{
$relation
->
index
}]
=
$record
;
}
else
{
}
else
{
$this
->
_related
[
$relation
->
name
][]
=
$record
;
$this
->
_related
[
$relation
->
name
][]
=
$record
;
}
}
...
...
framework/db/ar/BaseActiveQuery.php
View file @
c3216bd0
...
@@ -34,7 +34,7 @@ class BaseActiveQuery extends BaseQuery
...
@@ -34,7 +34,7 @@ class BaseActiveQuery extends BaseQuery
* @var string the name of the column that the result should be indexed by.
* @var string the name of the column that the result should be indexed by.
* This is only useful when the query result is returned as an array.
* This is only useful when the query result is returned as an array.
*/
*/
public
$index
By
;
public
$index
;
/**
/**
* @var boolean whether to return each record as an array. If false (default), an object
* @var boolean whether to return each record as an array. If false (default), an object
* of [[modelClass]] will be created to represent each record.
* of [[modelClass]] will be created to represent each record.
...
@@ -61,9 +61,9 @@ class BaseActiveQuery extends BaseQuery
...
@@ -61,9 +61,9 @@ class BaseActiveQuery extends BaseQuery
return
$this
;
return
$this
;
}
}
public
function
index
By
(
$column
)
public
function
index
(
$column
)
{
{
$this
->
index
By
=
$column
;
$this
->
index
=
$column
;
return
$this
;
return
$this
;
}
}
...
...
framework/db/ar/JoinElement.php
View file @
c3216bd0
...
@@ -111,8 +111,8 @@ class JoinElement extends \yii\base\Object
...
@@ -111,8 +111,8 @@ class JoinElement extends \yii\base\Object
continue
;
continue
;
}
}
if
(
$child
->
query
->
hasMany
)
{
if
(
$child
->
query
->
hasMany
)
{
if
(
$child
->
query
->
index
By
!==
null
)
{
if
(
$child
->
query
->
index
!==
null
)
{
$hash
=
$childRecord
[
$child
->
query
->
index
By
];
$hash
=
$childRecord
[
$child
->
query
->
index
];
}
else
{
}
else
{
$hash
=
serialize
(
$childRecord
->
getPrimaryKey
());
$hash
=
serialize
(
$childRecord
->
getPrimaryKey
());
}
}
...
...
tests/unit/framework/db/ar/ActiveRecordTest.php
View file @
c3216bd0
...
@@ -217,8 +217,8 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
...
@@ -217,8 +217,8 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase
$customers
=
Customer
::
find
()
->
order
(
'id'
)
->
asArray
()
->
all
();
$customers
=
Customer
::
find
()
->
order
(
'id'
)
->
asArray
()
->
all
();
$this
->
assertEquals
(
'user2'
,
$customers
[
1
][
'name'
]);
$this
->
assertEquals
(
'user2'
,
$customers
[
1
][
'name'
]);
// index
By
// index
$customers
=
Customer
::
find
()
->
order
(
'id'
)
->
index
By
(
'name'
)
->
all
();
$customers
=
Customer
::
find
()
->
order
(
'id'
)
->
index
(
'name'
)
->
all
();
$this
->
assertEquals
(
2
,
$customers
[
'user2'
][
'id'
]);
$this
->
assertEquals
(
2
,
$customers
[
'user2'
][
'id'
]);
}
}
...
...
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