Commit df22616c by Carsten Brandt

finished fix for redis null and boolean value storage

fixes #1311
parent f7fc1faa
...@@ -173,6 +173,7 @@ local pks={} ...@@ -173,6 +173,7 @@ local pks={}
local n=0 local n=0
local v=nil local v=nil
local i=0 local i=0
local key=$key
for k,pk in ipairs(allpks) do for k,pk in ipairs(allpks) do
$loadColumnValues $loadColumnValues
if $condition then if $condition then
...@@ -271,12 +272,13 @@ EOF; ...@@ -271,12 +272,13 @@ EOF;
if (is_bool($value)) { if (is_bool($value)) {
$value = (int)$value; $value = (int)$value;
} }
$column = $this->addColumn($column, $columns);
if ($value === null) { if ($value === null) {
$parts[] = "$column==nil"; $parts[] = "redis.call('HEXISTS',key .. ':a:' .. pk, ".$this->quoteValue($column).")==0";
} elseif ($value instanceof Expression) { } elseif ($value instanceof Expression) {
$column = $this->addColumn($column, $columns);
$parts[] = "$column==" . $value->expression; $parts[] = "$column==" . $value->expression;
} else { } else {
$column = $this->addColumn($column, $columns);
$value = $this->quoteValue($value); $value = $this->quoteValue($value);
$parts[] = "$column==$value"; $parts[] = "$column==$value";
} }
...@@ -359,7 +361,7 @@ EOF; ...@@ -359,7 +361,7 @@ EOF;
$value = isset($value[$column]) ? $value[$column] : null; $value = isset($value[$column]) ? $value[$column] : null;
} }
if ($value === null) { if ($value === null) {
$parts[] = "$columnAlias==nil"; $parts[] = "redis.call('HEXISTS',key .. ':a:' .. pk, ".$this->quoteValue($column).")==0";
} elseif ($value instanceof Expression) { } elseif ($value instanceof Expression) {
$parts[] = "$columnAlias==" . $value->expression; $parts[] = "$columnAlias==" . $value->expression;
} else { } else {
...@@ -378,11 +380,11 @@ EOF; ...@@ -378,11 +380,11 @@ EOF;
foreach ($values as $value) { foreach ($values as $value) {
$vs = []; $vs = [];
foreach ($inColumns as $column) { foreach ($inColumns as $column) {
$column = $this->addColumn($column, $columns);
if (isset($value[$column])) { if (isset($value[$column])) {
$vs[] = "$column==" . $this->quoteValue($value[$column]); $columnAlias = $this->addColumn($column, $columns);
$vs[] = "$columnAlias==" . $this->quoteValue($value[$column]);
} else { } else {
$vs[] = "$column==nil"; $vs[] = "redis.call('HEXISTS',key .. ':a:' .. pk, ".$this->quoteValue($column).")==0";
} }
} }
$vss[] = '(' . implode(' and ', $vs) . ')'; $vss[] = '(' . implode(' and ', $vs) . ')';
......
...@@ -33,6 +33,17 @@ class Order extends ActiveRecord ...@@ -33,6 +33,17 @@ class Order extends ActiveRecord
->via('orderItems')->indexBy('id'); ->via('orderItems')->indexBy('id');
} }
public function getItemsWithNullFK()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItemsWithNullFK');
}
public function getOrderItemsWithNullFK()
{
return $this->hasMany(OrderItemWithNullFK::className(), ['order_id' => 'id']);
}
public function getItemsInOrder1() public function getItemsInOrder1()
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) return $this->hasMany(Item::className(), ['id' => 'item_id'])
...@@ -52,8 +63,15 @@ class Order extends ActiveRecord ...@@ -52,8 +63,15 @@ class Order extends ActiveRecord
public function getBooks() public function getBooks()
{ {
return $this->hasMany(Item::className(), ['id' => 'item_id']) return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItems', ['order_id' => 'id']); ->via('orderItems')
//->where(['category_id' => 1]); ->where(['category_id' => 1]);
}
public function getBooksWithNullFK()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItemsWithNullFK')
->where(['category_id' => 1]);
} }
public function beforeSave($insert) public function beforeSave($insert)
......
...@@ -143,24 +143,6 @@ class ActiveRecordTest extends RedisTestCase ...@@ -143,24 +143,6 @@ class ActiveRecordTest extends RedisTestCase
} }
public function testFindNullValues()
{
// https://github.com/yiisoft/yii2/issues/1311
$this->markTestSkipped('Redis does not store/find null values correctly.');
}
public function testUnlinkAll()
{
// https://github.com/yiisoft/yii2/issues/1311
$this->markTestSkipped('Redis does not store/find null values correctly.');
}
public function testUnlink()
{
// https://github.com/yiisoft/yii2/issues/1311
$this->markTestSkipped('Redis does not store/find null values correctly.');
}
public function testFindEagerViaRelationPreserveOrder() public function testFindEagerViaRelationPreserveOrder()
{ {
$this->markTestSkipped('Redis does not support orderBy.'); $this->markTestSkipped('Redis does not support orderBy.');
...@@ -267,6 +249,7 @@ class ActiveRecordTest extends RedisTestCase ...@@ -267,6 +249,7 @@ class ActiveRecordTest extends RedisTestCase
public function testFindColumn() public function testFindColumn()
{ {
// TODO this test is duplicated because of missing orderBy support in redis
$this->assertEquals(['user1', 'user2', 'user3'], Customer::find()->column('name')); $this->assertEquals(['user1', 'user2', 'user3'], Customer::find()->column('name'));
// TODO $this->assertEquals(['user3', 'user2', 'user1'], Customer::find()->orderBy(['name' => SORT_DESC])->column('name')); // TODO $this->assertEquals(['user3', 'user2', 'user1'], Customer::find()->orderBy(['name' => SORT_DESC])->column('name'));
} }
......
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