1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace LaravelDoctrine\Fluent\Relations; |
4
|
|
|
|
5
|
|
|
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder; |
6
|
|
|
use Doctrine\ORM\Mapping\Builder\ManyToManyAssociationBuilder; |
7
|
|
|
use Doctrine\ORM\Mapping\Builder\OneToManyAssociationBuilder; |
8
|
|
|
use LaravelDoctrine\Fluent\Relations\Traits\Indexable; |
9
|
|
|
use LaravelDoctrine\Fluent\Relations\Traits\ManyTo; |
10
|
|
|
use LaravelDoctrine\Fluent\Relations\Traits\Orderable; |
11
|
|
|
use LaravelDoctrine\Fluent\Relations\Traits\Ownable; |
12
|
|
|
use LaravelDoctrine\Fluent\Relations\Traits\Owning; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @method $this mappedBy($fieldName) |
16
|
|
|
* @method $this inversedBy($fieldName) |
17
|
|
|
* @method $this orphanRemoval() |
18
|
|
|
*/ |
19
|
|
|
class ManyToMany extends AbstractRelation |
20
|
|
|
{ |
21
|
|
|
use ManyTo, Owning, Ownable, Orderable, Indexable; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ManyToManyAssociationBuilder |
25
|
|
|
*/ |
26
|
|
|
protected $association; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* @param ClassMetadataBuilder $builder |
30
|
|
|
* @param string $relation |
31
|
|
|
* @param string $entity |
32
|
|
|
* |
33
|
|
|
* @return OneToManyAssociationBuilder |
34
|
|
|
*/ |
35
|
44 |
|
protected function createAssociation(ClassMetadataBuilder $builder, $relation, $entity) |
36
|
|
|
{ |
37
|
44 |
|
return $this->builder->createManyToMany($relation, $entity); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @param string $table |
42
|
|
|
* |
43
|
|
|
* @return $this |
44
|
|
|
*/ |
45
|
3 |
|
public function joinTable($table) |
46
|
|
|
{ |
47
|
3 |
|
$this->association->setJoinTable($table); |
48
|
|
|
|
49
|
3 |
|
return $this; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @param string $joinColumn |
54
|
|
|
* @param string $references |
55
|
|
|
* @param bool $unique |
56
|
|
|
* |
57
|
|
|
* @return $this |
58
|
|
|
*/ |
59
|
8 |
|
public function joinColumn($joinColumn, $references = 'id', $unique = false) |
60
|
|
|
{ |
61
|
8 |
|
$this->addJoinColumn(null, $joinColumn, $references, false, $unique); |
62
|
|
|
|
63
|
8 |
|
return $this; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* @param string $foreignKey |
68
|
|
|
* @param string $references |
69
|
|
|
* @param bool $unique |
70
|
|
|
* |
71
|
|
|
* @return $this |
72
|
|
|
*/ |
73
|
2 |
|
public function foreignKey($foreignKey, $references = 'id', $unique = false) |
74
|
|
|
{ |
75
|
2 |
|
return $this->joinColumn($foreignKey, $references, $unique); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* @param string $foreignKey |
80
|
|
|
* @param string $references |
81
|
|
|
* @param bool $unique |
82
|
|
|
* |
83
|
|
|
* @return $this |
84
|
|
|
*/ |
85
|
4 |
|
public function source($foreignKey, $references = 'id', $unique = false) |
86
|
|
|
{ |
87
|
4 |
|
return $this->joinColumn($foreignKey, $references, $unique); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* @param string $inverseKey |
92
|
|
|
* @param string $references |
93
|
|
|
* @param bool $unique |
94
|
|
|
* |
95
|
|
|
* @return $this |
96
|
|
|
*/ |
97
|
5 |
|
public function inverseKey($inverseKey, $references = 'id', $unique = false) |
98
|
|
|
{ |
99
|
5 |
|
$this->association->addInverseJoinColumn($inverseKey, $references, false, $unique); |
100
|
|
|
|
101
|
5 |
|
return $this; |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @param string $inverseKey |
106
|
|
|
* @param string $references |
107
|
|
|
* @param bool $unique |
108
|
|
|
* |
109
|
|
|
* @return $this |
110
|
|
|
*/ |
111
|
3 |
|
public function target($inverseKey, $references = 'id', $unique = false) |
112
|
|
|
{ |
113
|
3 |
|
return $this->inverseKey($inverseKey, $references, $unique); |
114
|
|
|
} |
115
|
|
|
} |
116
|
|
|
|