From c3216bd05e08dd9ab075f24f75bb89cc6f3aee6d Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Sat, 10 Mar 2012 14:01:11 -0500 Subject: [PATCH] renamed indexBy to be index. --- framework/db/ar/ActiveFinder.php | 12 ++++++------ framework/db/ar/ActiveRecord.php | 4 ++-- framework/db/ar/BaseActiveQuery.php | 6 +++--- framework/db/ar/JoinElement.php | 4 ++-- tests/unit/framework/db/ar/ActiveRecordTest.php | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/framework/db/ar/ActiveFinder.php b/framework/db/ar/ActiveFinder.php index c30c342..5d34409 100644 --- a/framework/db/ar/ActiveFinder.php +++ b/framework/db/ar/ActiveFinder.php @@ -74,21 +74,21 @@ class ActiveFinder extends \yii\base\Object $rows = $command->queryAll(); $records = array(); if ($query->asArray) { - if ($query->indexBy === null) { + if ($query->index === null) { return $rows; } foreach ($rows as $row) { - $records[$row[$query->indexBy]] = $row; + $records[$row[$query->index]] = $row; } } else { $class = $query->modelClass; - if ($query->indexBy === null) { + if ($query->index === null) { foreach ($rows as $row) { $records[] = $class::create($row); } } else { foreach ($rows as $row) { - $records[$row[$query->indexBy]] = $class::create($row); + $records[$row[$query->index]] = $class::create($row); } } } @@ -125,10 +125,10 @@ class ActiveFinder extends \yii\base\Object $joinTree->createRecord($row); } - if ($query->indexBy !== null) { + if ($query->index !== null) { $records = array(); foreach ($joinTree->records as $record) { - $records[$record[$query->indexBy]] = $record; + $records[$record[$query->index]] = $record; } return $records; } else { diff --git a/framework/db/ar/ActiveRecord.php b/framework/db/ar/ActiveRecord.php index 4ed4736..cb31f8d 100644 --- a/framework/db/ar/ActiveRecord.php +++ b/framework/db/ar/ActiveRecord.php @@ -524,8 +524,8 @@ abstract class ActiveRecord extends Model public function addRelatedRecord($relation, $record) { if ($relation->hasMany) { - if ($relation->indexBy !== null) { - $this->_related[$relation->name][$record->{$relation->indexBy}] = $record; + if ($relation->index !== null) { + $this->_related[$relation->name][$record->{$relation->index}] = $record; } else { $this->_related[$relation->name][] = $record; } diff --git a/framework/db/ar/BaseActiveQuery.php b/framework/db/ar/BaseActiveQuery.php index c53a4f2..61dc664 100644 --- a/framework/db/ar/BaseActiveQuery.php +++ b/framework/db/ar/BaseActiveQuery.php @@ -34,7 +34,7 @@ class BaseActiveQuery extends BaseQuery * @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. */ - public $indexBy; + public $index; /** * @var boolean whether to return each record as an array. If false (default), an object * of [[modelClass]] will be created to represent each record. @@ -61,9 +61,9 @@ class BaseActiveQuery extends BaseQuery return $this; } - public function indexBy($column) + public function index($column) { - $this->indexBy = $column; + $this->index = $column; return $this; } diff --git a/framework/db/ar/JoinElement.php b/framework/db/ar/JoinElement.php index 72b740a..371e6a6 100644 --- a/framework/db/ar/JoinElement.php +++ b/framework/db/ar/JoinElement.php @@ -111,8 +111,8 @@ class JoinElement extends \yii\base\Object continue; } if ($child->query->hasMany) { - if ($child->query->indexBy !== null) { - $hash = $childRecord[$child->query->indexBy]; + if ($child->query->index !== null) { + $hash = $childRecord[$child->query->index]; } else { $hash = serialize($childRecord->getPrimaryKey()); } diff --git a/tests/unit/framework/db/ar/ActiveRecordTest.php b/tests/unit/framework/db/ar/ActiveRecordTest.php index e9bbb67..636be01 100644 --- a/tests/unit/framework/db/ar/ActiveRecordTest.php +++ b/tests/unit/framework/db/ar/ActiveRecordTest.php @@ -217,8 +217,8 @@ class ActiveRecordTest extends \yiiunit\MysqlTestCase $customers = Customer::find()->order('id')->asArray()->all(); $this->assertEquals('user2', $customers[1]['name']); - // indexBy - $customers = Customer::find()->order('id')->indexBy('name')->all(); + // index + $customers = Customer::find()->order('id')->index('name')->all(); $this->assertEquals(2, $customers['user2']['id']); }