public function delete_from_database() { $this->runCallbacks('destroy', function () { $this->delete_file(); self::connection()->executeSql('UPDATE pools SET post_count = post_count - 1 WHERE id IN (SELECT pool_id FROM pools_posts WHERE post_id = ?)', $this->id); self::connection()->executeSql('UPDATE tags SET post_count = post_count - 1 WHERE id IN (SELECT tag_id FROM posts_tags WHERE post_id = ?)', $this->id); # MI: Destroying pool posts manually so their histories are deleted by foreign keys. # This is done in Pool too. This could be done with a MySQL trigger. PoolPost::destroyAll('post_id = ?', $this->id); self::connection()->executeSql("DELETE FROM posts WHERE id = ?", $this->id); }); }
protected function destroy_pool_posts() { PoolPost::destroyAll('pool_id = ?', $this->id); }