function &fetch($params = array(), $sql_params = array())
 {
     $sql_params['columns'][] = ', m.file_name, m.mime_type, m.etag, m.size ';
     $sql_params['tables'][] = ', media as m ';
     $sql_params['conditions'][] = ' AND tn.media_id=m.id ';
     $records = parent::fetch($params, $sql_params);
     return $records;
 }
  function & fetch($params=array(), $sql_params=array())
  {
    if(!$records = parent :: fetch($params, $sql_params))
      return array();

    $images_ids = array();

    foreach($records as $record)
      $images_ids[] = "{$record['object_id']}";

    $ids = '('. implode(',', $images_ids) . ')';

    $sql =
        "SELECT
        iv.image_id,
        iv.media_id,
        iv.variation,
        iv.width,
        iv.height,
        m.size,
        m.mime_type,
        m.file_name,
        m.etag,
        m.id
        FROM image_variation iv, media m
        WHERE iv.media_id = m.id AND
        iv.image_id IN {$ids}";

    $db =& db_factory :: instance();

    $db->sql_exec($sql);

    if(!$images_variations = $db->get_array())
      return $records;

    foreach($images_variations as $variation_data)
    {
      foreach($records as $id => $record)
      {
        if($record['object_id'] == $variation_data['image_id'])
        {
          $records[$id]['variations'][$variation_data['variation']] = $variation_data;
          break;
        }
      }
    }

    return $records;
  }