protected function getSortTableClauseForIds(DataList $list, $ids)
 {
     if (is_array($ids)) {
         $value = 'IN (' . implode(', ', array_map('intval', $ids)) . ')';
     } else {
         $value = '= ' . (int) $ids;
     }
     if ($list instanceof ManyManyList) {
         $extra = $list->getExtraFields();
         $key = $list->getLocalKey();
         $foreignKey = $list->getForeignKey();
         $foreignID = (int) $list->getForeignID();
         if ($extra && array_key_exists($this->getSortField(), $extra)) {
             return sprintf('"%s" %s AND "%s" = %d', $key, $value, $foreignKey, $foreignID);
         }
     }
     return "\"ID\" {$value}";
 }