Thank you to anyone who has already donated - your generous donations helped make three months of treatment possible.

My brother Nate continues to fight stage IV Hodgkin's lymphoma. He's just 31, with a wife and baby girl. They have no active income (since he's been unable to return to work), no insurance, and cannot afford the treatment he needs. Nate and his family need your help. Please consider a donation, every dollar helps. Thanks.


Query

VoteItem.find(:all, :joins => :votes, :select => "votes.*, votes.count vote_count", :conditions => {:votes => {:user => @users}}, :group => "vote_items.id", :order => "vote_count DESC")

Error

Mysql::Error: Unknown column 'votes.count' in 'field list': SELECT votes.*, votes.count vote_count FROM `vote_items` INNER JOIN `votes` ON `votes`.voteable_id = `vote_items`.id AND `votes`.voteable_type = 'VoteItem' WHERE (`votes`.`user` IN (1,656,1311,1966,2097,2228,2883,3538,3669,4717,5765,6027,6420)) GROUP BY vote_items.id ORDER BY vote_count DESC
ActiveRecord::StatementInvalid: Mysql::Error: Unknown column 'votes.count' in 'field list': SELECT votes.*, votes.count vote_count FROM `vote_items`   INNER JOIN `votes` ON `votes`.voteable_id = `vote_items`.id AND `votes`.voteable_type = 'VoteItem' WHERE (`votes`.`user` IN (1,656,1311,1966,2097,2228,2883,3538,3669,4717,5765,6027,6420))  GROUP BY vote_items.id ORDER BY vote_count DESC

There is no votes.countin vote_items. 

Here are the tables.

TableVoteItem

VoteItemid: integer, option: string, info: string, created_at: datetime, updated_at: datetime, vote_topic_id: integer

Table Vote

Voteid: integer, vote: boolean, voteable_id: integer, voteable_type: string, voter_id: integer, voter_type: string, created_at: datetime, updated_at: datetime

Vote.rb

class Vote < ActiveRecord::Base

    named_scope :for_voter,    lambda { |*args| {:conditions => ["voter_id = ? AND voter_type = ?", args.first.id, args.first.type.name]} }
    named_scope :for_voteable, lambda { |*args| {:conditions => ["voteable_id = ? AND voteable_type = ?", args.first.id, args.first.type.name]} }
    named_scope :recent,       lambda { |*args| {:conditions => ["created_at > ?", (args.first || 2.weeks.ago).to_s(:db)]} }
    named_scope :descending, :order => "created_at DESC"

    # NOTE: Votes belong to the "voteable" interface, and also to voters
    belongs_to :voteable, :polymorphic => true
    belongs_to :voter, :polymorphic => true


    attr_accessible :vote, :voter, :voteable


end