1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace yiiunit\data\ar\redis;
use yii\redis\RecordSchema;
class Order extends ActiveRecord
{
public function getCustomer()
{
return $this->hasOne('Customer', array('id' => 'customer_id'));
}
public function getOrderItems()
{
return $this->hasMany('OrderItem', array('order_id' => 'id'));
}
public function getItems()
{
return $this->hasMany('Item', array('id' => 'item_id'))
->via('orderItems', function($q) {
// additional query configuration
});
}
public function getBooks()
{
return $this->hasMany('Item', array('id' => 'item_id'))
->via('orderItems', array('order_id' => 'id'));
//->where(array('category_id' => 1));
}
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
$this->create_time = time();
return true;
} else {
return false;
}
}
public static function getTableSchema()
{
return new RecordSchema(array(
'name' => 'orders',
'primaryKey' => array('id'),
'columns' => array(
'id' => 'integer',
'customer_id' => 'integer',
'create_time' => 'integer',
'total' => 'decimal',
)
));
}
}