Passed
Pull Request — master (#339)
by Sergei
02:59
created

Customer::getProfileQuery()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\ActiveRecord\Tests\Stubs\MagicActiveRecord;
6
7
use Yiisoft\ActiveRecord\ActiveQuery;
8
use Yiisoft\ActiveRecord\MagicalActiveRecord;
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
class Customer extends MagicalActiveRecord
20
{
21
    public const STATUS_ACTIVE = 1;
22
    public const STATUS_INACTIVE = 2;
23
24
    /**
25
     * @var int|string
26
     */
27
    public $status2;
28
    /**
29
     * @var int|string|null
30
     */
31
    public $sumTotal;
32
33
    public function getTableName(): string
34
    {
35
        return 'customer';
36
    }
37
38
    public function getName(): string
39
    {
40
        return $this->getAttribute('name');
41
    }
42
43
    public function getProfileQuery(): ActiveQuery
44
    {
45
        return $this->hasOne(Profile::class, ['id' => 'profile_id']);
46
    }
47
48
    public function getOrdersPlainQuery(): ActiveQuery
49
    {
50
        return $this->hasMany(Order::class, ['customer_id' => 'id']);
51
    }
52
53
    public function getOrdersQuery(): ActiveQuery
54
    {
55
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->orderBy('[[id]]');
56
    }
57
58
    public function getOrdersNoOrderQuery(): ActiveQuery
59
    {
60
        return $this->hasMany(Order::class, ['customer_id' => 'id']);
61
    }
62
63
    public function getExpensiveOrdersQuery(): ActiveQuery
64
    {
65
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->andWhere('[[total]] > 50')->orderBy('id');
66
    }
67
68
    public function getItemQuery(): void
69
    {
70
    }
71
72
    public function getOrdersWithItemsQuery(): ActiveQuery
73
    {
74
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->with('orderItems');
75
    }
76
77
    public function getExpensiveOrdersWithNullFKQuery(): ActiveQuery
78
    {
79
        return $this->hasMany(
80
            OrderWithNullFK::class,
81
            ['customer_id' => 'id']
82
        )->andWhere('[[total]] > 50')->orderBy('id');
83
    }
84
85
    public function getOrdersWithNullFKQuery(): ActiveQuery
86
    {
87
        return $this->hasMany(OrderWithNullFK::class, ['customer_id' => 'id'])->orderBy('id');
88
    }
89
90
    public function getOrders2Query(): ActiveQuery
91
    {
92
        return $this->hasMany(Order::class, ['customer_id' => 'id'])->inverseOf('customer2')->orderBy('id');
93
    }
94
95
    /** deeply nested table relation */
96
    public function getOrderItemsQuery(): ActiveQuery
97
    {
98
        $rel = $this->hasMany(Item::class, ['id' => 'item_id']);
99
100
        return $rel->viaTable('order_item', ['order_id' => 'id'], function ($q) {
101
            /* @var $q ActiveQuery */
102
            $q->viaTable('order', ['customer_id' => 'id']);
103
        })->orderBy('id');
104
    }
105
106
    public function setOrdersReadOnly(): void
107
    {
108
    }
109
110
    public function getOrderItems2Query(): ActiveQuery
111
    {
112
        return $this->hasMany(OrderItem::class, ['order_id' => 'id'])
113
            ->via('ordersNoOrder');
114
    }
115
116
    public function getItems2Query(): ActiveQuery
117
    {
118
        return $this->hasMany(Item::class, ['id' => 'item_id'])
119
            ->via('orderItems2');
120
    }
121
}
122