Passed
Pull Request — master (#225)
by Def
06:55 queued 04:09
created

Customer::getItems()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\ActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\ActiveRecord;
9
10
/**
11
 * Class Customer.
12
 *
13
 * @property int $id
14
 * @property string $name
15
 * @property string $email
16
 * @property string $address
17
 * @property int $status
18
 *
19
 * @method CustomerQuery findBySql($sql, $params = []) static.
20
 */
21
class Customer extends ActiveRecord
22
{
23
    public const STATUS_ACTIVE = 1;
24
    public const STATUS_INACTIVE = 2;
25
26
    /**
27
     * @var int|string
28
     */
29
    public $status2;
30
    /**
31
     * @var int|string|null
32
     */
33
    public $sumTotal;
34
35
    public function getTableName(): string
36
    {
37
        return 'customer';
38
    }
39
40
    public function getProfile(): ActiveQuery
41
    {
42
        return $this->hasOne(Profile::class, ['id' => 'profile_id']);
43
    }
44
45
    public function getOrdersPlain(): ActiveQuery
46
    {
47
        return $this->hasMany(Order::class, ['customer_id' => 'id']);
48
    }
49
50
    public function getOrders(): ActiveQuery
51
    {
52
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->orderBy('{{order}}.[[id]]');
53
    }
54
55
    public function getExpensiveOrders(): ActiveQuery
56
    {
57
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->andWhere('[[total]] > 50')->orderBy('id');
58
    }
59
60
    public function getItem(): void
61
    {
62
    }
63
64
    public function getOrdersWithItems(): ActiveQuery
65
    {
66
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->with('orderItems');
67
    }
68
69
    public function getExpensiveOrdersWithNullFK(): ActiveQuery
70
    {
71
        return $this->hasMany(
72
            OrderWithNullFK::class,
73
            ['customer_id' => 'id']
74
        )->andWhere('[[total]] > 50')->orderBy('id');
75
    }
76
77
    public function getOrdersWithNullFK(): ActiveQuery
78
    {
79
        return $this->hasMany(OrderWithNullFK::class, ['customer_id' => 'id'])->orderBy('id');
80
    }
81
82
    public function getOrders2(): ActiveQuery
83
    {
84
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->inverseOf('customer2')->orderBy('id');
85
    }
86
87
    /** deeply nested table relation */
88
    public function getOrderItems(): ActiveQuery
89
    {
90
        $rel = $this->hasMany(Item::class, ['id' => 'item_id']);
91
92
        return $rel->viaTable('order_item', ['order_id' => 'id'], function ($q) {
93
            /* @var $q ActiveQuery */
94
            $q->viaTable('order', ['customer_id' => 'id']);
95
        })->orderBy('id');
96
    }
97
98
    public function setOrdersReadOnly(): void
99
    {
100
    }
101
102
    public function getOrderItems2()
103
    {
104
        return $this->hasMany(OrderItem::class, ['order_id' => 'id'])
105
            ->via('orders');
106
    }
107
108
    public function getItems()
109
    {
110
        return $this->hasMany(Item::class, ['id' => 'item_id'])
111
            ->via('orderItems2');
112
    }
113
}
114