1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of slick/orm package |
5
|
|
|
* |
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
7
|
|
|
* file that was distributed with this source code. |
8
|
|
|
*/ |
9
|
|
|
|
10
|
|
|
namespace Slick\Orm\Mapper\Relation; |
11
|
|
|
|
12
|
|
|
use Slick\Orm\Descriptor\EntityDescriptorInterface; |
13
|
|
|
use Slick\Orm\Descriptor\Field\FieldDescriptor; |
14
|
|
|
use Slick\Orm\Descriptor\Field\FieldsCollection; |
15
|
|
|
use Slick\Orm\Orm; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Useful methods for relations |
19
|
|
|
* |
20
|
|
|
* @package Slick\Orm\Mapper\Relation |
21
|
|
|
* @author Filipe Silva <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
trait RelationsUtilityMethods |
24
|
|
|
{ |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* Gets the parent or related entity descriptor |
28
|
|
|
* |
29
|
|
|
* @return EntityDescriptorInterface |
30
|
|
|
*/ |
31
|
|
|
abstract public function getParentEntityDescriptor(); |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* Gets parent entity class name |
35
|
|
|
* |
36
|
|
|
* @return string |
37
|
|
|
*/ |
38
|
|
|
abstract public function getParentEntity(); |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Gets the parent entity primary key field name |
42
|
|
|
* |
43
|
|
|
* @return string |
44
|
|
|
*/ |
45
|
4 |
|
public function getParentPrimaryKey() |
46
|
|
|
{ |
47
|
4 |
|
return $this->getParentEntityDescriptor() |
48
|
4 |
|
->getPrimaryKey() |
49
|
4 |
|
->getField(); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Gets parent entity repository |
54
|
|
|
* |
55
|
|
|
* @return \Slick\Orm\Repository\EntityRepository |
56
|
|
|
*/ |
57
|
2 |
|
public function getParentRepository() |
58
|
|
|
{ |
59
|
2 |
|
return Orm::getRepository($this->getParentEntity()); |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Gets the entity mapper of parent entity repository |
64
|
|
|
* |
65
|
|
|
* @return \Slick\Orm\EntityMapperInterface |
66
|
|
|
*/ |
67
|
2 |
|
public function getParentEntityMapper() |
68
|
|
|
{ |
69
|
2 |
|
return $this->getParentRepository() |
70
|
2 |
|
->getEntityMapper(); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Gets parent entity table name |
75
|
|
|
* |
76
|
|
|
* @return string |
77
|
|
|
*/ |
78
|
4 |
|
public function getParentTableName() |
79
|
|
|
{ |
80
|
4 |
|
return $this->getParentEntityDescriptor() |
81
|
4 |
|
->getTableName(); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* Get parent entity fields collection |
86
|
|
|
* |
87
|
|
|
* @return FieldsCollection|FieldDescriptor[] |
88
|
|
|
*/ |
89
|
2 |
|
public function getParentFields() |
90
|
|
|
{ |
91
|
2 |
|
return $this->getParentEntityDescriptor() |
92
|
2 |
|
->getFields(); |
93
|
|
|
} |
94
|
|
|
} |