I have 2 models:
class Core < ActiveRecord::Base
has_many :votes
has_many :messages
end
class Vote < ActiveRecord::Base
belongs_to:core
end
class Message < ActiveRecord::Base
belongs_to:core
end
In php for view the last cores names with number of messages and sum of
votes i do so:
mysql_query(“SELECT
name,votes_join.total_votes,messages_join.number_messages
FROM core LEFT JOIN (SELECT sum(vote),core_id FROM votes GROUP BY
core_id) as votes_join on votes_join.core_id=core.id LEFT JOIN (SELECT
count(*) as number_messages,core_id FROM messages GROUP BY core_id) as
messages_join on messages_join.core_id=core.id”)
Is possibile di it with find method of models??
How?
Thanks