diff --git a/app/controllers/admin/domain.php b/app/controllers/admin/domain.php
index facd370aa53dabefaeb04f157f5661411c8a34c9..e4bb9c8695e7348829b612a60d51794e992a4d1f 100644
--- a/app/controllers/admin/domain.php
+++ b/app/controllers/admin/domain.php
@@ -138,7 +138,7 @@ class Admin_DomainController extends AuthenticatedController
         CSRFProtection::verifyUnsafeRequest();
         $domain = new UserDomain($id);
 
-        if (count($domain->users) == 0) {
+        if ($domain->countUsers() === 0) {
             $domain->delete();
         } else {
             PageLayout::postError(_('Domänen, denen noch Personen zugewiesen sind, können nicht gelöscht werden.'));
diff --git a/app/views/admin/domain/index.php b/app/views/admin/domain/index.php
index 9b37517f2f338fd8ed3c8ee09c8cd8bef428d0dd..1d935eb1759f24c2aa61aaced6830c7bf6d056e4 100644
--- a/app/views/admin/domain/index.php
+++ b/app/views/admin/domain/index.php
@@ -28,13 +28,13 @@
                 <tr>
                     <td><?= htmlReady($domain->name) ?></td>
                     <td><?= htmlReady($domain->id) ?></td>
-                    <td><?= count($domain->users) ?></td>
-                    <td><?= count($domain->courses) ?></td>
+                    <td><?= $domain->countUsers() ?></td>
+                    <td><?= $domain->countCourses() ?></td>
                     <td class="actions">
                         <a href="<?= $controller->link_for("admin/domain/edit/{$domain->id}") ?>" data-dialog="size=auto">
                             <?= Icon::create('edit')->asImg(tooltip2(_('bearbeiten'))) ?>
                         </a>
-                    <? if (count($domain->users) === 0): ?>
+                    <? if ($domain->countUsers() === 0): ?>
                         <?= Icon::create('trash')->asInput(tooltip2(_('löschen')) + [
                             'class'        => 'text-top',
                             'formaction'   => $controller->url_for("admin/domain/delete/{$domain->id}"),
diff --git a/lib/models/UserDomain.php b/lib/models/UserDomain.php
index 44befce2c51608fcab433143fb38e236f7cdea23..8179082a0319a5afeaa05342671fa35eb1e3436d 100644
--- a/lib/models/UserDomain.php
+++ b/lib/models/UserDomain.php
@@ -48,6 +48,30 @@ class UserDomain extends SimpleORMap
         return self::findBySQL('1 ORDER BY name');
     }
 
+    /**
+     * Count the number of courses associated with this user domain.
+     *
+     * @return int number of courses
+     */
+    public function countCourses(): int
+    {
+        $query = 'SELECT COUNT(*) FROM seminar_userdomains WHERE userdomain_id = ?';
+
+        return (int) DBManager::get()->fetchColumn($query, [$this->id]);
+    }
+
+    /**
+     * Count the number of courses associated with this user domain.
+     *
+     * @return int number of users
+     */
+    public function countUsers(): int
+    {
+        $query = 'SELECT COUNT(*) FROM user_userdomains WHERE userdomain_id = ?';
+
+        return (int) DBManager::get()->fetchColumn($query, [$this->id]);
+    }
+
     /**
      * Add a user to this user domain.
      */