mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-10 23:50:38 +08:00
fixed unlink() for array valued attributes
return value would not be a valid array when json encoded after unlink(). fixes #6065
This commit is contained in:
@@ -5,6 +5,7 @@ Yii Framework 2 elasticsearch extension Change Log
|
||||
-----------------------
|
||||
|
||||
- Bug #5662: Elasticsearch AR updateCounters() now uses explicitly `groovy` script for updating making it compatible with ES >1.3.0 (cebe)
|
||||
- Bug #6065: `ActiveRecord::unlink()` was failing in some situations when working with relations via array valued attributes (cebe)
|
||||
|
||||
|
||||
2.0.0 October 12, 2014
|
||||
|
||||
@@ -1295,7 +1295,7 @@ abstract class BaseActiveRecord extends Model implements ActiveRecordInterface
|
||||
if (($key = array_search($model->$a, $this->$b, false)) !== false) {
|
||||
$values = $this->$b;
|
||||
unset($values[$key]);
|
||||
$this->$b = $values;
|
||||
$this->$b = array_values($values);
|
||||
}
|
||||
} else {
|
||||
$this->$b = null;
|
||||
|
||||
@@ -812,6 +812,31 @@ class ActiveRecordTest extends ElasticSearchTestCase
|
||||
$this->assertFalse(isset($items[2]));
|
||||
}
|
||||
|
||||
/**
|
||||
* https://github.com/yiisoft/yii2/issues/6065
|
||||
*/
|
||||
public function testArrayAttributeRelationUnLinkBrokenArray()
|
||||
{
|
||||
/* @var $order Order */
|
||||
$order = Order::find()->where(['id' => 1])->one();
|
||||
|
||||
$itemIds = $order->itemsArray;
|
||||
$removeId = reset($itemIds);
|
||||
$item = Item::get($removeId);
|
||||
$order->unlink('itemsByArrayValue', $item);
|
||||
$this->afterSave();
|
||||
|
||||
$items = $order->itemsByArrayValue;
|
||||
$this->assertEquals(1, count($items));
|
||||
$this->assertFalse(isset($items[$removeId]));
|
||||
|
||||
// check also after refresh
|
||||
$this->assertTrue($order->refresh());
|
||||
$items = $order->itemsByArrayValue;
|
||||
$this->assertEquals(1, count($items));
|
||||
$this->assertFalse(isset($items[$removeId]));
|
||||
}
|
||||
|
||||
/**
|
||||
* @expectedException \yii\base\NotSupportedException
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user