/** * @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)); }
public function getExpensiveOrders() { return $this->hasMany(Order::className(), ['customer_id' => 'id'])->filter(['range' => ['total' => ['gte' => 50]]])->orderBy('id'); }
public function testUpdatePk() { $pkName = 'id'; $orderItem = Order::findOne([$pkName => 2]); $this->assertEquals(2, $orderItem->primaryKey); $this->assertEquals(2, $orderItem->oldPrimaryKey); $this->assertEquals(2, $orderItem->{$pkName}); // $this->setExpectedException('yii\base\InvalidCallException'); $orderItem->{$pkName} = 13; $this->assertEquals(13, $orderItem->primaryKey); $this->assertEquals(2, $orderItem->oldPrimaryKey); $this->assertEquals(13, $orderItem->{$pkName}); $orderItem->save(); $this->afterSave(); $this->assertEquals(13, $orderItem->primaryKey); $this->assertEquals(13, $orderItem->oldPrimaryKey); $this->assertEquals(13, $orderItem->{$pkName}); $this->assertNull(Order::findOne([$pkName => 2])); $this->assertNotNull(Order::findOne([$pkName => 13])); }
public function getOrders() { return $this->hasMany(Order::className(), ['customer_id' => 'id'])->orderBy('created_at'); }
public function getOrder() { return $this->hasOne(Order::className(), ['id' => 'order_id']); }