From 72b07245f44c73ed41bfcca2465a9ee34426a922 Mon Sep 17 00:00:00 2001 From: winter Date: Thu, 19 Dec 2024 20:59:18 +0000 Subject: implement follow relationships (untested) does NOT implement the actual behaviour behind follows (receiving posts and such) --- Digitigrade/Model.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'Digitigrade/Model.php') 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 -- cgit v1.3