From 179618c6e943e1e02801741df5d9339e21d59626 Mon Sep 17 00:00:00 2001 From: Carsten Brandt Date: Mon, 30 Sep 2013 15:39:04 +0200 Subject: [PATCH] fixed empty result in findByPk list --- framework/yii/redis/ActiveQuery.php | 9 ++++++--- tests/unit/framework/redis/ActiveRecordTest.php | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/framework/yii/redis/ActiveQuery.php b/framework/yii/redis/ActiveQuery.php index fff25cb..d16d944 100644 --- a/framework/yii/redis/ActiveQuery.php +++ b/framework/yii/redis/ActiveQuery.php @@ -315,9 +315,12 @@ class ActiveQuery extends \yii\base\Component foreach($pks as $pk) { if (++$i > $start && ($this->limit === null || $i <= $start + $this->limit)) { $key = $modelClass::tableName() . ':a:' . $modelClass::buildKey($pk); - $data[] = $db->executeCommand('HGETALL', array($key)); - if ($type === 'One' && $this->orderBy === null) { - break; + $result = $db->executeCommand('HGETALL', array($key)); + if (!empty($result)) { + $data[] = $result; + if ($type === 'One' && $this->orderBy === null) { + break; + } } } } diff --git a/tests/unit/framework/redis/ActiveRecordTest.php b/tests/unit/framework/redis/ActiveRecordTest.php index a6ac3ce..6d9efcd 100644 --- a/tests/unit/framework/redis/ActiveRecordTest.php +++ b/tests/unit/framework/redis/ActiveRecordTest.php @@ -97,6 +97,10 @@ class ActiveRecordTest extends RedisTestCase $this->assertEquals('user2', $customer->name); $customer = Customer::find(5); $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 $customerName = Customer::find()->where(array('id' => 2))->scalar('name');