TableRelations::linkTo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
1
<?php
2
3
/**
4
 * Bluz Framework Component
5
 *
6
 * @copyright Bluz PHP Team
7
 * @link      https://github.com/bluzphp/framework
8
 */
9
10
declare(strict_types=1);
11
12
namespace Bluz\Db\Traits;
13
14
use Bluz\Db\Relations;
15
16
/**
17
 * TableRelations
18
 *
19
 * @package  Bluz\Db\Traits
20
 * @author   Anton Shevchuk
21
 */
22
trait TableRelations
23
{
24
    /**
25
     * Setup relation "one to one" or "one to many"
26
     *
27
     * @param  string $key
28
     * @param  string $model
29
     * @param  string $foreign
30
     *
31
     * @return void
32
     */
33
    public function linkTo($key, $model, $foreign): void
34
    {
35
        Relations::setRelation($this->model, $key, $model, $foreign);
36
    }
37
38
    /**
39
     * Setup relation "many to many"
40
     * [table1-key] [table1_key-table2-table3_key] [table3-key]
41
     *
42
     * @param  string $model
43
     * @param  string $link
44
     *
45
     * @return void
46
     */
47
    public function linkToMany($model, $link): void
48
    {
49
        Relations::setRelations($this->model, $model, [$link]);
50
    }
51
}
52