1 | <?php |
||
16 | abstract class Relation |
||
17 | { |
||
18 | /** |
||
19 | * @var \Pulsar\Model |
||
20 | */ |
||
21 | protected $localModel; |
||
22 | |||
23 | /** |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $localKey; |
||
27 | |||
28 | /** |
||
29 | * @var string |
||
30 | */ |
||
31 | protected $foreignModel; |
||
32 | |||
33 | /** |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $foreignKey; |
||
37 | |||
38 | /** |
||
39 | * @var \Pulsar\Query |
||
40 | */ |
||
41 | protected $query; |
||
42 | |||
43 | /** |
||
44 | * @var bool |
||
45 | */ |
||
46 | protected $empty; |
||
47 | |||
48 | /** |
||
49 | * @param Model $localModel |
||
50 | * @param string $localKey identifying key on local model |
||
51 | * @param string $foreignModel foreign model class |
||
52 | * @param string $foreignKey identifying key on foreign model |
||
53 | */ |
||
54 | public function __construct(Model $localModel, $localKey, $foreignModel, $foreignKey) |
||
65 | |||
66 | /** |
||
67 | * Gets the local model of the relationship. |
||
68 | * |
||
69 | * @return \Pulsar\Model |
||
70 | */ |
||
71 | public function getLocalModel() |
||
75 | |||
76 | /** |
||
77 | * Gets the name of the foreign key of the relation model. |
||
78 | * |
||
79 | * @return string |
||
80 | */ |
||
81 | public function getLocalKey() |
||
85 | |||
86 | /** |
||
87 | * Gets the foreign model of the relationship. |
||
88 | * |
||
89 | * @return string |
||
90 | */ |
||
91 | public function getForeignModel() |
||
95 | |||
96 | /** |
||
97 | * Gets the name of the foreign key of the foreign model. |
||
98 | * |
||
99 | * @return string |
||
100 | */ |
||
101 | public function getForeignKey() |
||
105 | |||
106 | /** |
||
107 | * Returns the query instance for this relation. |
||
108 | * |
||
109 | * @return \Pulsar\Query |
||
110 | */ |
||
111 | public function getQuery() |
||
115 | |||
116 | /** |
||
117 | * Called to initialize the query. |
||
118 | */ |
||
119 | abstract protected function initQuery(); |
||
120 | |||
121 | /** |
||
122 | * Called to get the results of the relation query. |
||
123 | * |
||
124 | * @return mixed |
||
125 | */ |
||
126 | abstract public function getResults(); |
||
127 | |||
128 | /** |
||
129 | * Creates a new relationship model and attaches it to the owning model. |
||
130 | * |
||
131 | * @param array $values |
||
132 | * |
||
133 | * @return Model |
||
134 | */ |
||
135 | abstract public function create(array $values = []); |
||
136 | |||
137 | public function __call($method, $arguments) |
||
142 | } |
||
143 |