|
@@ 109-123 (lines=15) @@
|
| 106 |
|
/** |
| 107 |
|
* {@inheritdoc} |
| 108 |
|
*/ |
| 109 |
|
public function update() |
| 110 |
|
{ |
| 111 |
|
if (!$this->exists()) { |
| 112 |
|
throw new ActiveRecordException(sprintf('Can not update a non-existent active record entry to the `%s` table.', $this->getActiveRecordName())); |
| 113 |
|
} |
| 114 |
|
|
| 115 |
|
try { |
| 116 |
|
$pdoStatement = $this->getPdo()->prepare($this->getUpdateQuery()); |
| 117 |
|
$pdoStatement->execute(['id' => $this->getId()] + $this->getActiveRecordData()); |
| 118 |
|
} catch (\PDOException $e) { |
| 119 |
|
throw new ActiveRecordException(sprintf('Can not update active record entry %d to the `%s` table.', $this->getId(), $this->getActiveRecordName()), 0, $e); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
return $this; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
/** |
| 126 |
|
* Returns the update query. |
|
@@ 144-160 (lines=17) @@
|
| 141 |
|
/** |
| 142 |
|
* {@inheritdoc} |
| 143 |
|
*/ |
| 144 |
|
public function delete() |
| 145 |
|
{ |
| 146 |
|
if (!$this->exists()) { |
| 147 |
|
throw new ActiveRecordException(sprintf('Can not delete a non-existent active record entry from the `%s` table.', $this->getActiveRecordName())); |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
try { |
| 151 |
|
$pdoStatement = $this->getPdo()->prepare($this->getDeleteQuery()); |
| 152 |
|
$pdoStatement->execute(['id' => $this->getId()]); |
| 153 |
|
|
| 154 |
|
$this->setId(null); |
| 155 |
|
} catch (\PDOException $e) { |
| 156 |
|
throw new ActiveRecordException(sprintf('Can not delete active record entry %d from the `%s` table.', $this->getId(), $this->getActiveRecordName()), 0, $e); |
| 157 |
|
} |
| 158 |
|
|
| 159 |
|
return $this; |
| 160 |
|
} |
| 161 |
|
|
| 162 |
|
/** |
| 163 |
|
* Returns the delete query. |