diff --git a/extensions/redis/ActiveQuery.php b/extensions/redis/ActiveQuery.php index 1bf8f68..dce68e0 100644 --- a/extensions/redis/ActiveQuery.php +++ b/extensions/redis/ActiveQuery.php @@ -124,14 +124,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface $row[$dataRow[$i++]] = $dataRow[$i++]; } - $class = $this->modelClass; - $modelInstance = $class::instantiate($row); - foreach ($modelInstance->attributes() as $attribute) { - if (!isset($row[$attribute])) { - $row[$attribute] = null; - } - } - $rows[] = $row; } if (!empty($rows)) { @@ -173,14 +165,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface } if ($this->asArray) { $model = $row; - - $class = $this->modelClass; - $modelInstance = $class::instantiate($row); - foreach($modelInstance->attributes() as $attribute) { - if (!isset($model[$attribute])) { - $model[$attribute] = null; - } - } } else { /* @var $class ActiveRecord */ $class = $this->modelClass; diff --git a/tests/unit/extensions/redis/ActiveRecordTest.php b/tests/unit/extensions/redis/ActiveRecordTest.php index bb68e4a..0bc4dd8 100644 --- a/tests/unit/extensions/redis/ActiveRecordTest.php +++ b/tests/unit/extensions/redis/ActiveRecordTest.php @@ -153,6 +153,44 @@ class ActiveRecordTest extends RedisTestCase $this->markTestSkipped('Redis does not support orderBy.'); } + /** + * overridden because null values are not part of the asArray result in redis + */ + public function testFindAsArray() + { + /* @var $customerClass \yii\db\ActiveRecordInterface */ + $customerClass = $this->getCustomerClass(); + + // asArray + $customer = $customerClass::find()->where(['id' => 2])->asArray()->one(); + $this->assertEquals([ + 'id' => 2, + 'email' => 'user2@example.com', + 'name' => 'user2', + 'address' => 'address2', + 'status' => 1, + ], $customer); + + // find all asArray + $customers = $customerClass::find()->asArray()->all(); + $this->assertEquals(3, count($customers)); + $this->assertArrayHasKey('id', $customers[0]); + $this->assertArrayHasKey('name', $customers[0]); + $this->assertArrayHasKey('email', $customers[0]); + $this->assertArrayHasKey('address', $customers[0]); + $this->assertArrayHasKey('status', $customers[0]); + $this->assertArrayHasKey('id', $customers[1]); + $this->assertArrayHasKey('name', $customers[1]); + $this->assertArrayHasKey('email', $customers[1]); + $this->assertArrayHasKey('address', $customers[1]); + $this->assertArrayHasKey('status', $customers[1]); + $this->assertArrayHasKey('id', $customers[2]); + $this->assertArrayHasKey('name', $customers[2]); + $this->assertArrayHasKey('email', $customers[2]); + $this->assertArrayHasKey('address', $customers[2]); + $this->assertArrayHasKey('status', $customers[2]); + } + public function testStatisticalFind() { // find count, sum, average, min, max, scalar