1 | <?php |
||
14 | trait HasRelationsRecordsTrait |
||
15 | { |
||
16 | use RecordsTrait; |
||
17 | |||
18 | /** |
||
19 | * The loaded relationships for the model table. |
||
20 | * @var Relation[] |
||
21 | */ |
||
22 | protected $relations = null; |
||
23 | |||
24 | protected $relationTypes = ['belongsTo', 'hasMany', 'hasAndBelongsToMany']; |
||
25 | |||
26 | |||
27 | /** |
||
28 | * Get a specified relationship. |
||
29 | * @param string $relation |
||
30 | * @return null|Relation |
||
31 | * @throws \Exception |
||
32 | */ |
||
33 | 1 | public function getRelation($relation) |
|
39 | |||
40 | /** |
||
41 | * Check if the model needs to initRelations |
||
42 | * @return void |
||
43 | * @throws \Exception |
||
44 | */ |
||
45 | 1 | protected function checkInitRelations() |
|
51 | |||
52 | /** |
||
53 | * @throws \Exception |
||
54 | */ |
||
55 | protected function initRelations() |
||
62 | |||
63 | /** |
||
64 | * @param string $type |
||
65 | * @throws \Exception |
||
66 | */ |
||
67 | protected function initRelationsType($type) |
||
74 | |||
75 | /** |
||
76 | * @param string $type |
||
77 | * @param $array |
||
78 | * @throws \Exception |
||
79 | */ |
||
80 | public function initRelationsFromArray($type, $array) |
||
88 | |||
89 | /** |
||
90 | * @param string $type |
||
91 | * @param string $name |
||
92 | * @param array $params |
||
93 | * @return Relation |
||
94 | * @throws \Exception |
||
95 | */ |
||
96 | 1 | protected function initRelation($type, $name, $params) |
|
106 | |||
107 | /** |
||
108 | * @param string $type |
||
109 | * @return \Nip\Records\Relations\Relation |
||
110 | */ |
||
111 | 2 | public function newRelation($type) |
|
120 | |||
121 | /** |
||
122 | * @param string $type |
||
123 | * @return string |
||
124 | */ |
||
125 | 3 | public function getRelationClass($type) |
|
131 | |||
132 | /** |
||
133 | * @param $name |
||
134 | * @param array $params |
||
135 | * @return Relation |
||
136 | * @throws \Exception |
||
137 | */ |
||
138 | 1 | public function belongsTo($name, $params = []) |
|
142 | |||
143 | /** |
||
144 | * @param $name |
||
145 | * @param array $params |
||
146 | * @return Relation |
||
147 | * @throws \Exception |
||
148 | */ |
||
149 | public function hasMany($name, $params = []) |
||
153 | |||
154 | /** @noinspection PhpMethodNamingConventionInspection |
||
155 | * @param $name |
||
156 | * @param array $params |
||
157 | * @return Relation |
||
158 | * @throws \Exception |
||
159 | */ |
||
160 | public function HABTM($name, $params = []) |
||
164 | |||
165 | /** |
||
166 | * @param $name |
||
167 | * @param array $params |
||
168 | * @return Relation |
||
169 | * @throws \Exception |
||
170 | */ |
||
171 | public function morphTo($name, $params = []) |
||
175 | |||
176 | /** |
||
177 | * @param $name |
||
178 | * @param array $params |
||
179 | * @return Relation |
||
180 | * @throws \Exception |
||
181 | */ |
||
182 | public function morphMany($name, $params = []) |
||
186 | |||
187 | /** |
||
188 | * @param $name |
||
189 | * @param array $params |
||
190 | * @return Relation |
||
191 | * @throws \Exception |
||
192 | */ |
||
193 | public function morphToMany($name, $params = []) |
||
197 | |||
198 | /** |
||
199 | * @param $name |
||
200 | * @param array $params |
||
201 | * @return MorphToMany |
||
202 | * @throws \Exception |
||
203 | */ |
||
204 | public function morphedByMany($name, $params = []) |
||
211 | |||
212 | /** |
||
213 | * Determine if the given relation is loaded. |
||
214 | * @param string $key |
||
215 | * @return bool |
||
216 | * @throws \Exception |
||
217 | */ |
||
218 | public function hasRelation($key) |
||
224 | |||
225 | /** |
||
226 | * Set the specific relationship in the model. |
||
227 | * @param string $relation |
||
228 | * @param mixed $value |
||
229 | * @return $this |
||
230 | * @throws \Exception |
||
231 | */ |
||
232 | public function setRelation($relation, $value) |
||
239 | |||
240 | /** |
||
241 | * @param HasRelationsRecordTrait $from |
||
|
|||
242 | * @param HasRelationsRecordTrait $to |
||
243 | * @return HasRelationsRecordTrait |
||
244 | * @throws \Exception |
||
245 | */ |
||
246 | public function cloneRelations($from, $to) |
||
267 | |||
268 | /** |
||
269 | * Get all the loaded relations for the instance. |
||
270 | * @return array |
||
271 | * @throws \Exception |
||
272 | */ |
||
273 | public function getRelations() |
||
279 | |||
280 | /** |
||
281 | * Set the entire relations array on the model. |
||
282 | * @param array $relations |
||
283 | * @return $this |
||
284 | */ |
||
285 | public function setRelations(array $relations) |
||
291 | } |
||
292 |