コード例 #1
0
ファイル: ActiveRecordTest.php プロジェクト: trntv/yii2
 /**
  * @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));
 }
コード例 #2
0
 public function getExpensiveOrders()
 {
     return $this->hasMany(Order::className(), ['customer_id' => 'id'])->filter(['range' => ['total' => ['gte' => 50]]])->orderBy('id');
 }
コード例 #3
0
ファイル: ActiveRecordTest.php プロジェクト: sciurodont/yii2
 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]));
 }
コード例 #4
0
ファイル: Customer.php プロジェクト: rajanishtimes/basicyii
 public function getOrders()
 {
     return $this->hasMany(Order::className(), ['customer_id' => 'id'])->orderBy('created_at');
 }
コード例 #5
0
ファイル: OrderItem.php プロジェクト: rajanishtimes/basicyii
 public function getOrder()
 {
     return $this->hasOne(Order::className(), ['id' => 'order_id']);
 }