Commit ece300ac by Carsten Brandt

removed null value adjustment in redis ActiveQuery

asArray will not include null valued keys
parent df22616c
...@@ -124,14 +124,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface ...@@ -124,14 +124,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface
$row[$dataRow[$i++]] = $dataRow[$i++]; $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; $rows[] = $row;
} }
if (!empty($rows)) { if (!empty($rows)) {
...@@ -173,14 +165,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface ...@@ -173,14 +165,6 @@ class ActiveQuery extends Component implements ActiveQueryInterface
} }
if ($this->asArray) { if ($this->asArray) {
$model = $row; $model = $row;
$class = $this->modelClass;
$modelInstance = $class::instantiate($row);
foreach($modelInstance->attributes() as $attribute) {
if (!isset($model[$attribute])) {
$model[$attribute] = null;
}
}
} else { } else {
/* @var $class ActiveRecord */ /* @var $class ActiveRecord */
$class = $this->modelClass; $class = $this->modelClass;
......
...@@ -153,6 +153,44 @@ class ActiveRecordTest extends RedisTestCase ...@@ -153,6 +153,44 @@ class ActiveRecordTest extends RedisTestCase
$this->markTestSkipped('Redis does not support orderBy.'); $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() public function testStatisticalFind()
{ {
// find count, sum, average, min, max, scalar // find count, sum, average, min, max, scalar
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment