diff --git a/lib/models/FileRef.php b/lib/models/FileRef.php
index 9cc24388141068b350eccbf2c01f4cb617b64991..c4e09f1b3653ca8480815a9366ded6508a87bba7 100644
--- a/lib/models/FileRef.php
+++ b/lib/models/FileRef.php
@@ -489,7 +489,7 @@ class FileRef extends SimpleORMap implements PrivacyObject, FeedbackRange
             AND `folders`.`range_type` = 'user' ";
         $sql_params = [];
         if ($user_id) {
-            $sql .= " AND `folders`.`user_id` = :user_id";
+            $sql .= " AND `folders`.`range_id` = :user_id";
             $sql_params['user_id'] = $user_id;
         }
         if (($begin instanceof DateTime) && ($end instanceof DateTime)) {