| @@ 87-103 (lines=17) @@ | ||
| 84 | /** |
|
| 85 | * {@inheritdoc} |
|
| 86 | */ |
|
| 87 | public function update() |
|
| 88 | { |
|
| 89 | if (!$this->exists()) { |
|
| 90 | throw new ActiveRecordException(sprintf('Can not update a non-existent active record entry to the `%s` table.', $this->getActiveRecordTable())); |
|
| 91 | } |
|
| 92 | ||
| 93 | try { |
|
| 94 | (new Query($this->getPdo(), $this->getActiveRecordTable())) |
|
| 95 | ->update($this->getActiveRecordColumns()) |
|
| 96 | ->where('id', '=', $this->getId()) |
|
| 97 | ->execute(); |
|
| 98 | } catch (\PDOException $e) { |
|
| 99 | throw new ActiveRecordException($e->getMessage(), 0, $e); |
|
| 100 | } |
|
| 101 | ||
| 102 | return $this; |
|
| 103 | } |
|
| 104 | ||
| 105 | /** |
|
| 106 | * {@inheritdoc} |
|
| @@ 108-126 (lines=19) @@ | ||
| 105 | /** |
|
| 106 | * {@inheritdoc} |
|
| 107 | */ |
|
| 108 | public function delete() |
|
| 109 | { |
|
| 110 | if (!$this->exists()) { |
|
| 111 | throw new ActiveRecordException(sprintf('Can not delete a non-existent active record entry from the `%s` table.', $this->getActiveRecordTable())); |
|
| 112 | } |
|
| 113 | ||
| 114 | try { |
|
| 115 | (new Query($this->getPdo(), $this->getActiveRecordTable())) |
|
| 116 | ->delete() |
|
| 117 | ->where('id', '=', $this->getId()) |
|
| 118 | ->execute(); |
|
| 119 | ||
| 120 | $this->setId(null); |
|
| 121 | } catch (\PDOException $e) { |
|
| 122 | throw new ActiveRecordException($e->getMessage(), 0, $e); |
|
| 123 | } |
|
| 124 | ||
| 125 | return $this; |
|
| 126 | } |
|
| 127 | ||
| 128 | /** |
|
| 129 | * {@inheritdoc} |
|