Commit df22616c by Carsten Brandt

finished fix for redis null and boolean value storage

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