1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelDoctrine\Fluent\Relations\Traits; |
4
|
|
|
|
5
|
|
|
use LaravelDoctrine\Fluent\Relations\JoinColumn; |
6
|
|
|
|
7
|
|
|
trait ManyTo |
8
|
|
|
{ |
9
|
|
|
/** |
10
|
|
|
* @var JoinColumn[] |
11
|
|
|
*/ |
12
|
|
|
protected $joinColumns = []; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Build the association |
16
|
|
|
*/ |
17
|
81 |
|
public function build() |
18
|
|
|
{ |
19
|
81 |
|
foreach ($this->getJoinColumns() as $column) { |
20
|
56 |
|
$this->getAssociation()->addJoinColumn( |
21
|
56 |
|
$column->getJoinColumn(), |
22
|
56 |
|
$column->getReferenceColumn(), |
23
|
56 |
|
$column->isNullable(), |
24
|
56 |
|
$column->isUnique(), |
25
|
56 |
|
$column->getOnDelete(), |
26
|
56 |
|
$column->getColumnDefinition() |
27
|
56 |
|
); |
28
|
81 |
|
} |
29
|
|
|
|
30
|
81 |
|
parent::build(); |
31
|
80 |
|
} |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param string $relation |
35
|
|
|
* @param string|null $joinColumn |
36
|
|
|
* @param string|null $referenceColumn |
37
|
|
|
* @param bool|false $nullable |
38
|
|
|
* @param bool|false $unique |
39
|
|
|
* @param string|null $onDelete |
40
|
|
|
* @param string|null $columnDefinition |
41
|
|
|
* |
42
|
|
|
* @return $this |
43
|
|
|
*/ |
44
|
127 |
|
public function addJoinColumn( |
45
|
|
|
$relation, |
46
|
|
|
$joinColumn = null, |
47
|
|
|
$referenceColumn = null, |
48
|
|
|
$nullable = false, |
49
|
|
|
$unique = false, |
50
|
|
|
$onDelete = null, |
51
|
|
|
$columnDefinition = null |
52
|
|
|
) { |
53
|
127 |
|
$joinColumn = new JoinColumn( |
54
|
127 |
|
$this->getNamingStrategy(), |
55
|
127 |
|
$relation, |
56
|
127 |
|
$joinColumn, |
57
|
127 |
|
$referenceColumn, |
58
|
127 |
|
$nullable, |
59
|
127 |
|
$unique, |
60
|
127 |
|
$onDelete, |
61
|
|
|
$columnDefinition |
62
|
127 |
|
); |
63
|
|
|
|
64
|
127 |
|
$this->pushJoinColumn($joinColumn); |
65
|
|
|
|
66
|
127 |
|
return $this; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param JoinColumn $column |
71
|
|
|
*/ |
72
|
127 |
|
protected function pushJoinColumn(JoinColumn $column) |
73
|
|
|
{ |
74
|
127 |
|
$this->joinColumns[] = $column; |
75
|
127 |
|
} |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @return JoinColumn[] |
79
|
|
|
*/ |
80
|
83 |
|
public function getJoinColumns() |
81
|
|
|
{ |
82
|
83 |
|
return $this->joinColumns; |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @return \Doctrine\ORM\Mapping\Builder\AssociationBuilder |
87
|
|
|
*/ |
88
|
|
|
abstract public function getAssociation(); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @return \Doctrine\ORM\Mapping\NamingStrategy |
92
|
|
|
*/ |
93
|
|
|
abstract public function getNamingStrategy(); |
94
|
|
|
} |
95
|
|
|
|