Commit 1b4d894c by Carsten Brandt

created test for #5341

parent 79815252
......@@ -30,4 +30,14 @@ class Category extends ActiveRecord
return $this->hasMany(Item::className(), ['category_id' => 'id'])
->onCondition(['item.id' => [1, 2, 3]]);
}
public function getOrderItems()
{
return $this->hasMany(OrderItem::className(), ['item_id' => 'id'])->via('items');
}
public function getOrders()
{
return $this->hasMany(Order::className(), ['id' => 'order_id'])->via('orderItems');
}
}
......@@ -176,6 +176,34 @@ class ActiveRecordTest extends DatabaseTestCase
$this->assertEquals(2, $items[1]->id);
}
/**
* https://github.com/yiisoft/yii2/issues/5341
*
* Issue: Plan 1 -- * Account * -- * User
* Our Tests: Category 1 -- * Item * -- * Order
*/
public function testDeeplyNestedTableRelation2()
{
/* @var $category Category */
$category = Category::findOne(1);
$this->assertNotNull($category);
$orders = $category->orders;
$this->assertEquals(2, count($orders));
$this->assertInstanceOf(Order::className(), $orders[0]);
$this->assertInstanceOf(Order::className(), $orders[1]);
$ids = [$orders[0]->id, $orders[1]->id];
sort($ids);
$this->assertEquals([1, 3], $ids);
$category = Category::findOne(2);
$this->assertNotNull($category);
$orders = $category->orders;
$this->assertEquals(1, count($orders));
$this->assertInstanceOf(Order::className(), $orders[0]);
$this->assertEquals(2, $orders[0]->id);
}
public function testStoreNull()
{
$record = new NullValues();
......
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