| @@ 472-489 (lines=18) @@ | ||
| 469 | /** |
|
| 470 | * {@inheritdoc} |
|
| 471 | */ |
|
| 472 | public function update() |
|
| 473 | { |
|
| 474 | foreach ($this->registeredUpdateHooks as $colName => $fn) { |
|
| 475 | // @TODO: Would it be better to pass the Query to the function? |
|
| 476 | $fn(); |
|
| 477 | } |
|
| 478 | ||
| 479 | try { |
|
| 480 | (new Query($this->getPdo(), $this->getActiveRecordTable())) |
|
| 481 | ->update($this->getActiveRecordColumns()) |
|
| 482 | ->where('id', '=', $this->getId()) |
|
| 483 | ->execute(); |
|
| 484 | } catch (\PDOException $e) { |
|
| 485 | throw new ActiveRecordException($e->getMessage(), 0, $e); |
|
| 486 | } |
|
| 487 | ||
| 488 | return $this; |
|
| 489 | } |
|
| 490 | ||
| 491 | /** |
|
| 492 | * {@inheritdoc} |
|
| @@ 494-513 (lines=20) @@ | ||
| 491 | /** |
|
| 492 | * {@inheritdoc} |
|
| 493 | */ |
|
| 494 | public function delete() |
|
| 495 | { |
|
| 496 | foreach ($this->registeredDeleteHooks as $colName => $fn) { |
|
| 497 | // @TODO: Would it be better to pass the Query to the function? |
|
| 498 | $fn(); |
|
| 499 | } |
|
| 500 | ||
| 501 | try { |
|
| 502 | (new Query($this->getPdo(), $this->getActiveRecordTable())) |
|
| 503 | ->delete() |
|
| 504 | ->where('id', '=', $this->getId()) |
|
| 505 | ->execute(); |
|
| 506 | ||
| 507 | $this->setId(null); |
|
| 508 | } catch (\PDOException $e) { |
|
| 509 | throw new ActiveRecordException($e->getMessage(), 0, $e); |
|
| 510 | } |
|
| 511 | ||
| 512 | return $this; |
|
| 513 | } |
|
| 514 | ||
| 515 | /** |
|
| 516 | * {@inheritdoc} |
|