= DataMapper.repository.adapter.select( "SELECT #{field.robotize} as \"col\", COUNT(*) as \"times\" FROM items GROUP BY #{field.robotize} ORDER BY \"times\" desc") items.each do |item| occurrences[field][item[:col]] = item[:times] end if (others = occurrences[field].select{|k,v| v==1}.size) > 1 occurrences[field].delete_if{|k,v| v==1} occurrences[field]["Other"] = others end end