<?php

namespace App\Models;

use App\Core\Model;

class DocumentCategory extends Model
{
    protected $table = 'document_categories';
    protected $primaryKey = 'id';

    public function getWithCounts()
    {
        $stmt = $this->db->query("SELECT c.*, (SELECT COUNT(*) FROM documents WHERE category_id = c.id) as document_count FROM {$this->table} c ORDER BY c.sort_order ASC");
        return $stmt->fetchAll(\PDO::FETCH_OBJ);
    }
}
