You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.6 KiB

13 years ago
<?php
namespace yiiunit\data\ar;
/**
* Class Order
*
* @property integer $id
* @property integer $customer_id
* @property integer $create_time
* @property string $total
*/
13 years ago
class Order extends ActiveRecord
{
12 years ago
public static function tableName()
13 years ago
{
return 'tbl_order';
}
13 years ago
public function getCustomer()
13 years ago
{
return $this->hasOne(Customer::className(), ['id' => 'customer_id']);
12 years ago
}
public function getOrderItems()
12 years ago
{
return $this->hasMany(OrderItem::className(), ['order_id' => 'id']);
12 years ago
}
public function getItems()
12 years ago
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
12 years ago
->via('orderItems', function ($q) {
// additional query configuration
})->orderBy('id');
12 years ago
}
public function getItemsInOrder1()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItems', function ($q) {
$q->orderBy(['subtotal' => SORT_ASC]);
})->orderBy('name');
}
public function getItemsInOrder2()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->via('orderItems', function ($q) {
$q->orderBy(['subtotal' => SORT_DESC]);
})->orderBy('name');
}
public function getBooks()
13 years ago
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->viaTable('tbl_order_item', ['order_id' => 'id'])
->where(['category_id' => 1]);
12 years ago
}
12 years ago
public function getBooks2()
{
return $this->hasMany(Item::className(), ['id' => 'item_id'])
->onCondition(['category_id' => 1])
->viaTable('tbl_order_item', ['order_id' => 'id']);
}
12 years ago
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->create_time = time();
return true;
} else {
return false;
}
}
}