diff --git a/include/class.thread.php b/include/class.thread.php
index 8a1f42ecf0ccce1ef02528dff661e7321900ce4c..fad99db935f4479c5189344bd8d9b6e495a67647 100644
--- a/include/class.thread.php
+++ b/include/class.thread.php
@@ -475,10 +475,10 @@ Class ThreadEntry {
             return 0;
 
         // TODO: Add a unique index to TICKET_ATTACHMENT_TABLE (file_id,
-        // ticket_id), and remove this block
+        // ref_id), and remove this block
         if ($id = db_result(db_query('SELECT attach_id FROM '.TICKET_ATTACHMENT_TABLE
-                .' WHERE file_id='.db_input($fileId).' AND ticket_id='
-                .db_input($this->getTicketId()))))
+                .' WHERE file_id='.db_input($fileId).' AND ref_id='
+                .db_input($this->getId()))))
             return $id;
 
         $sql ='INSERT IGNORE INTO '.TICKET_ATTACHMENT_TABLE.' SET created=NOW() '