# Wyszukiwanie wedug wieku, pci i miejsca pobytu
def self.find_by_asl(params)
  where =[]
  .
  .
  .
  where << "gender = :gender" unless params[:gender].blank?
  
  # Ustawia ograniczenia odlegoci w SQL
  zip_code = params[:zip_code]
  unless zip_code.blank? and params[:miles].blank?
    location = GeoDatum.find_by_zip_code(zip_code)
    distance = sql_distance_away(location)
    where << "#{distance} <= :miles"
  end
  
  if where.empty?
    []
  else
    find(:all,
         :joins => "LEFT JOIN geo_data ON geo_data.zip_code = 
         ?specs.zip_code",
         :conditions => [where.join(" AND "), params], 
         :order => "last_name, first_name")
  end
end

