diff options
| author | winter | 2024-12-19 20:59:18 +0000 |
|---|---|---|
| committer | winter | 2024-12-19 20:59:18 +0000 |
| commit | 72b07245f44c73ed41bfcca2465a9ee34426a922 (patch) | |
| tree | 57372703100ad792c95c665a568aabe8a763bfdf /Digitigrade/Model.php | |
| parent | 1e070a7a0097c74f8ac30678d39267f19c76f9f6 (diff) | |
implement follow relationships (untested)
does NOT implement the actual behaviour behind follows (receiving posts and such)
Diffstat (limited to 'Digitigrade/Model.php')
| -rw-r--r-- | Digitigrade/Model.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/Digitigrade/Model.php b/Digitigrade/Model.php index 80a6d91..0db27ef 100644 --- a/Digitigrade/Model.php +++ b/Digitigrade/Model.php @@ -10,8 +10,8 @@ abstract class Model { } /** - * @return ?string a condition for a WHERE clause if this object already - * exists in the database, or null otherwise + * @return ?string a condition for a WHERE clause that uniquely identifies + * this object if it already exists in the database, or null if not */ protected function getUpdateWhereClause(\PDO $db): ?string { if (isset($this->id) && static::find($this->{'id'}) != null) { @@ -241,4 +241,21 @@ abstract class Model { $this->saved = true; } + + /** + * Removes this record from the database. + * @return void + */ + public function remove() { + $db = Db::getInstance()->getPdo(); + $where = $this->getUpdateWhereClause($db); + if ($where == null) { + throw new \RuntimeException("object doesn't seem to exist in the database so i can't delete it"); + } + $classNameParts = explode('\\', static::class); + $className = $classNameParts[count($classNameParts) - 1]; + $tableName = self::mangleName($className); + + $db->exec("DELETE FROM $tableName WHERE $where"); + } }
\ No newline at end of file |
