@@ 225-236 (lines=12) @@ | ||
222 | * |
|
223 | * @param array|string|int $primary_key |
|
224 | */ |
|
225 | protected function update_primary_key($primary_key) |
|
226 | { |
|
227 | $model = $this->model; |
|
228 | $property = $model->primary; |
|
229 | ||
230 | if (!$property) |
|
231 | { |
|
232 | throw new \LogicException("Unable to update primary key, model `$model->id` doesn't define one."); |
|
233 | } |
|
234 | ||
235 | $this->$property = $primary_key; |
|
236 | } |
|
237 | ||
238 | /** |
|
239 | * Deletes the active record using its model. |
|
@@ 245-256 (lines=12) @@ | ||
242 | * |
|
243 | * @throws \Exception in attempt to delete a record from a model which primary key is empty. |
|
244 | */ |
|
245 | public function delete() |
|
246 | { |
|
247 | $model = $this->model; |
|
248 | $primary = $model->primary; |
|
249 | ||
250 | if (!$primary) |
|
251 | { |
|
252 | throw new \LogicException("Unable to delete record, model `$model->id` doesn't have a primary key."); |
|
253 | } |
|
254 | ||
255 | return $model->delete($this->$primary); |
|
256 | } |
|
257 | } |
|
258 |