Exemple #1
0
 /**
  * @expectedException \yii\base\NotSupportedException
  */
 public function testArrayAttributeRelationUnLinkAll()
 {
     /* @var $order Order */
     $order = Order::find()->where(['id' => 1])->one();
     $items = $order->itemsByArrayValue;
     $this->assertEquals(2, count($items));
     $this->assertTrue(isset($items[1]));
     $this->assertTrue(isset($items[2]));
     $order->unlinkAll('itemsByArrayValue');
     $this->afterSave();
     $items = $order->itemsByArrayValue;
     $this->assertEquals(0, count($items));
     // check also after refresh
     $this->assertTrue($order->refresh());
     $items = $order->itemsByArrayValue;
     $this->assertEquals(0, count($items));
 }
Exemple #2
0
 public function testFindEagerViaRelation()
 {
     $orders = Order::find()->with('items')->orderBy('created_at')->all();
     $this->assertEquals(3, count($orders));
     $order = $orders[0];
     $this->assertEquals(1, $order->id);
     $this->assertTrue($order->isRelationPopulated('items'));
     $this->assertEquals(2, count($order->items));
     $this->assertEquals(1, $order->items[0]->id);
     $this->assertEquals(2, $order->items[1]->id);
 }