Browse Source

fixed empty result in findByPk list

tags/2.0.0-beta
Carsten Brandt 11 years ago
parent
commit
179618c6e9
  1. 5
      framework/yii/redis/ActiveQuery.php
  2. 4
      tests/unit/framework/redis/ActiveRecordTest.php

5
framework/yii/redis/ActiveQuery.php

@ -315,12 +315,15 @@ class ActiveQuery extends \yii\base\Component
foreach($pks as $pk) { foreach($pks as $pk) {
if (++$i > $start && ($this->limit === null || $i <= $start + $this->limit)) { if (++$i > $start && ($this->limit === null || $i <= $start + $this->limit)) {
$key = $modelClass::tableName() . ':a:' . $modelClass::buildKey($pk); $key = $modelClass::tableName() . ':a:' . $modelClass::buildKey($pk);
$data[] = $db->executeCommand('HGETALL', array($key)); $result = $db->executeCommand('HGETALL', array($key));
if (!empty($result)) {
$data[] = $result;
if ($type === 'One' && $this->orderBy === null) { if ($type === 'One' && $this->orderBy === null) {
break; break;
} }
} }
} }
}
// TODO support orderBy // TODO support orderBy
switch($type) { switch($type) {

4
tests/unit/framework/redis/ActiveRecordTest.php

@ -97,6 +97,10 @@ class ActiveRecordTest extends RedisTestCase
$this->assertEquals('user2', $customer->name); $this->assertEquals('user2', $customer->name);
$customer = Customer::find(5); $customer = Customer::find(5);
$this->assertNull($customer); $this->assertNull($customer);
$customer = Customer::find(array('id' => array(5, 6, 1)));
$this->assertEquals(1, count($customer));
$customer = Customer::find()->where(array('id' => array(5, 6, 1)))->one();
$this->assertNotNull($customer);
// query scalar // query scalar
$customerName = Customer::find()->where(array('id' => 2))->scalar('name'); $customerName = Customer::find()->where(array('id' => 2))->scalar('name');

Loading…
Cancel
Save