How to get the parent comments (in a custom module)? I'm writing a module that uses flag to handle notifications, and one of the options is to be notified of replies to a given comment.

I can implement without problem hook_comment_publish($comment), but I want to get all of its parent comments so that I can pick up the users that flagged them.

So, how can I retrieve all the parent comments of a given comment (if any)? I noticed that in taxonomy there is a taxonomy_get_parents($tid) but I can't find anything similar for threatened comments.
This code does the trick:

  $threads = explode('.', $comment-&gt;thread);
  $thread = "";
  $pnids = array();
  for($i=0;$i&lt;(count($threads)-1);$i++){
        $thread .= $threads[$i];
        $local_thread = $thread."/";
        $result = db_query('SELECT c.cid FROM {comment} c WHERE c.nid = :nid AND c.thread = :thread AND c.status = :status',
        array(':nid' =&gt; $comment-&gt;nid, ':thread' =&gt; $local_thread, ':status'=&gt;'1'));
        foreach ($result as $record) {
            $pnids[] = $record-&gt;cid;
        }
        $thread .= ".";
  }


However this code produces 1 DB query for each parent. I don't know if it is feasible/better to include all the :thread in a single query with OR.