ダイジェストメーラーの目的で、ユーザーが自分のアプリを見ることができる回答を取得したいと考えています。
ユーザーは、すでに購読しているすべてのグループから、投票数が最も多い 5 つの回答のみを表示する必要があります。
協会:
Answer
# Returns 5 the most voted answers
#
scope :best, order("votes_count DESC")
belongs_to :user
belongs_to :group
User
belongs_to :group
has_many :answers, :dependent => :destroy
has_many :groups, through: :subscriptions
Group
has_many :subscriptions
has_many :users, through: :subscriptions
has_many :questions
has_many :answers
だから私はこれを行うための最良の方法を探しています:
class BestAnswers
def self.for_user(user)
answers = []
user.groups.each |group|
answers << group.answers
end
return answers
end
end